Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 buttons and movement combined
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
kythoon




PostPosted: Tue May 13, 2003 4:33 pm   Post subject: buttons and movement combined

in the attached program, i have figured out the movement of the character and now i am wanting to put the buttons on the bottom for the user to use. if i use GUI.ProcessEvent, the screen is blank Confused how do i fix that so that the user can move and click on buttons on the same time?

Also how do i return back to the screen after one of the buttons are pressed?

Finally how do i make the computer reconize that the character is in the door way? I think you have to check the location of the door way to the character location. I dont mind if it goes through walls though.

thanks for the help

tell me if i forgot ne files.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Tue May 13, 2003 4:49 pm   Post subject: (No subject)

seems you forgot all of the files Confused

the way GUI.ProcessEvent works, I figure - it would work if you'd stick it into a process and let it run there in a loop.

I donno what you mean by "return" back to screen... just call the procedure for the "screen" you were using before.

To check if you're in a doorway, you compare character location to the door location. If they're identical (or whithin reasonable distance) you may continue.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
kythoon




PostPosted: Tue May 13, 2003 5:45 pm   Post subject: (No subject)

sorry about that Rolling Eyes
Homer_simpson




PostPosted: Tue May 13, 2003 6:00 pm   Post subject: (No subject)

code:
/*
 Still Need

 -open new screen when character moves into house or castle
 -leave town
 -quest help
 -battles
 */
import GUI
setscreen ("graphics:800;600,nobuttonbar,title:RPG")

const MARGIN := 45

var archerDefence : int
var archerMana : int
var backgroundHeight : int
var backgroundPic : int
var backgroundWidth : int
var backgroundX : int
var backgroundY : int
var baughtItem : string
var characterClass : string
var characterLevel : int
var characterMovementDistance : int := 4
var characterName : string
var chars : array char of boolean
var continue : string (1)
var currentLifeTotal : int
var currentMoneyTotal : int
var delayTime : int
var finalClass : string
var finalClassPic : int
var finalClassPicHeight : int
var finalClassPicWidth : int
var finalClassPicX : int
var finalClassPicY : int
var guideViewingCounter := 0
var leaveTownButton : int
var proceedToCastle : string
var questReminderButton : int
var quitGameButton : int
var totalLifeTotal : int
var viewCharacterGuide : string (1)
var viewGameGuide : string (1)
var warriorDefence : int
var warriorMana : int
var wizardDefence : int
var wizardMana : int


% Initialization
characterLevel := 1
currentLifeTotal := 30
totalLifeTotal := 30
currentMoneyTotal := 15
% warriorMana := 8
% warriorDefence := 10
% archerMana := 12
% archerDefence := 5
% wizardMana := 20
% wizardDefence := 2
delayTime := 2500

% Data on character
procedure characterData
    put repeat ("*", 20)
    put "Name:    ", characterName
    put "Class:   ", characterClass
    put "Level:   ", characterLevel
    put "Money:   ", currentMoneyTotal
    put "Life:    ", currentLifeTotal, " / ", totalLifeTotal
    put repeat ("*", 20)
end characterData

% Leave Town
procedure leaveTown
    cls
    locate (10, 10)
    put "Coming later."
    View.Update
    delay (1000)
end leaveTown

% Quest Help
procedure questHelp
    cls
    locate (10, 10)
    put "Coming later."
    View.Update
    delay (1000)
    % then return to main screen
end questHelp

% Quit Game
procedure quitGame
    cls
    locate (10, 10)
    put "Coming later."
    View.Update
    GUI.Quit
    return
end quitGame

% PNext Screen
procedure goOnToNext
    put skip, "Press any key to continue" ..
    getch (continue)
    cls
end goOnToNext

% Delay procedure
procedure TextDelay (text : string)
    for i : 1 .. length (text)
        put text (i) ..
        delay (5)
    end for
    put skip
end TextDelay


finalClassPic := Pic.FileNew ("warrior.bmp")
backgroundPic := Pic.FileNew ("town2.bmp")

finalClassPicWidth := Pic.Width (finalClassPic)
finalClassPicHeight := Pic.Height (finalClassPic)

backgroundWidth := Pic.Width (backgroundPic)
backgroundHeight := Pic.Height (backgroundPic)

backgroundX := (backgroundWidth - maxx) div 2
backgroundY := (backgroundHeight - maxy) div 2

finalClassPicX := (backgroundWidth - finalClassPicWidth) div 2
finalClassPicY := (backgroundHeight - finalClassPicHeight) div 2

setscreen ("offscreenonly")

loop
    Input.KeyDown (chars)
    if chars (KEY_LEFT_ARROW) then
        finalClassPicX -= 2
    elsif chars (KEY_RIGHT_ARROW) then
        finalClassPicX += 2
    end if
    if chars (KEY_UP_ARROW) then
        finalClassPicY += 2
    elsif chars (KEY_DOWN_ARROW) then
        finalClassPicY -= 2
    end if

    if finalClassPicX - MARGIN < 0 then
        finalClassPicX := MARGIN
    elsif finalClassPicX + finalClassPicWidth > backgroundWidth - MARGIN then
        finalClassPicX := backgroundWidth - MARGIN - finalClassPicWidth
    end if

    if finalClassPicX - backgroundX < MARGIN then
        backgroundX := finalClassPicX - MARGIN
    elsif (finalClassPicX + finalClassPicWidth) - backgroundX > maxx - MARGIN then
        backgroundX := finalClassPicX + finalClassPicWidth - maxx + MARGIN
    end if

    if finalClassPicY - MARGIN < 0 then
        finalClassPicY := MARGIN
    elsif finalClassPicY + finalClassPicHeight > backgroundHeight - MARGIN then
        finalClassPicY := backgroundHeight - MARGIN - finalClassPicHeight
    end if

    if finalClassPicY - backgroundY < MARGIN then
        backgroundY := finalClassPicY - MARGIN
    elsif (finalClassPicY + finalClassPicHeight) - backgroundY > maxy - MARGIN then
        backgroundY := finalClassPicY + finalClassPicHeight - maxy + MARGIN
    end if

    cls
    Pic.Draw (backgroundPic, -backgroundX, -backgroundY, picCopy)
    Pic.Draw (finalClassPic, finalClassPicX - backgroundX, finalClassPicY - backgroundY, picMerge)

    % Buttons
    Draw.FillBox (0, 0, maxx, 40, brown)
    leaveTownButton := GUI.CreateButtonFull (10, 5, 200, "Leave Town",
        leaveTown, 0, '^L', true)
    questReminderButton := GUI.CreateButtonFull (290, 5, 200, "Remeber Quest",
        questHelp, 0, '^R', false)
    quitGameButton := GUI.CreateButtonFull (590, 5, 200, "Quit the Game",
        quitGame, 0, '^Q', false)
    exit when GUI.ProcessEvent
    % loop
    %     exit when GUI.ProcessEvent
    % end loop
    View.Update

end loop

I believe this is what you wanted....
kythoon




PostPosted: Tue May 13, 2003 6:30 pm   Post subject: (No subject)

yup, thanks Very Happy


any idea how to get the location the door way when change the screen when character is there.

thanks for the help homer
Homer_simpson




PostPosted: Tue May 13, 2003 8:06 pm   Post subject: (No subject)

you can use the distance formula to detect if the character is close enough to go inside the room... and you also need to prevent yer character from going through the walls =/
kythoon




PostPosted: Tue May 13, 2003 8:45 pm   Post subject: (No subject)

ok, but would the coordinates of the picture door way change each time the picture, the background, is moved.
Homer_simpson




PostPosted: Tue May 13, 2003 9:20 pm   Post subject: (No subject)

hmmm... well u could use another method.... u could use whatdotcolor to see if there's a wall in front of u using the colors...it's prett lame but it'll do...
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: