Hello, this is my first post in newcommers, with probably more to come since I am now delving into 2d game development.
First of all, here is my main code:
Rem Project: The Tarinna Duel
Rem Created: Saturday, June 04, 2011
Rem ***** Main Source File *****
set display mode 1024, 600, 32
sync on : sync rate 60 : sync
set dir "Data/"
load image "IGScreen.png", 1
load image "PlayerIdle.png", 2
load image "PlayerAttack.png", 3
load image "spell1.png", 4
playerx = 500
playery = 400
pspellx = 500
pspelly = 50
enemyx = 500
enemyy = 50
espellx = 500
espelly = 400
tim = timer()
playerattacks = 0
spellcast = 0
do
cls
paste image 1, 0, 0
paste image 2, playerx, playery, 1
text 20, 20, str$(screen fps())
COSpikes = Text_Button(70, 50, "Circle Of Spikes")
if COSpikes = 1
spellcast = 1
COSpikes = 0
ENDIF
while spellcast = 1
cls
repeat
Elapsed=(Timer()-tim)/1000
paste image 1, 0, 0
paste image 3, playerx, playery - 20, 1
paste image 4, pspellx, pspelly, 1
UNTIL Elapsed = 1
if Elapsed = 1
text 100, 100, "It got to this point in the program"
Elapsed = 0
tim = timer()
spellcast = 0
exit
ENDIF
ENDWHILE
sync
LOOP
And here is my spell button code:
Rem ***** Included Source File *****
function text_button(x,y,text$)
tx = text width(text$)
ty = text height(text$)
pressed = 0
if mousex() < x+(tx/2) and mousex() > x-(tx/2)
if mousey() < y+(ty/2) and mousey() > y-(ty/2)
pressed = 1
endif
endif
if pressed = 1
ink rgb(200,0,0),0
else
ink rgb(255,0,0),0
endif
if pressed = 0 then hold = 0
center text x,y-(text size()/2),text$
if mouseclick() = 0 then pressed = 0
endfunction pressed
Now, my problem is that I want the player to cast a spell when he clicks the button labeled Circle of Spikes, and this works fine, except something is off with the timer, it kicks off all the code in the even at once instead of waiting for the timer.
Anyway, my main problem is that if I click the button again, the game just freezes with no error.
Can anyone see what I'm doing wrong please?
Thank you very much in advance.