How do I Cancel a button?
BlitzPlus Forums/BlitzPlus Programming/How do I Cancel a button?
| ||
What do I add to my game code if I want to cancel a key? For example, if I'm using key (57) for jumping, how do I make it so that when the character collides with a door, key (57) could no longer be used for jumping? For reference, I put the simplified game code below and I put notes directly on the section that I need help with (so it could be easier to find). Graphics 1640, 1000 Global HENRY HENRY = LoadAnimImage ("HenryMoveAroundIII.PNG",400,370,0,14) DOOR = LoadImage ("Door.png") BACKGROUND = LoadImage ("BLUEFOREST.jpg") BACKGROUND2 = LoadImage ("DockII.jpg") PLATFORM = LoadImage ("Platform.png") Type HENRY Field x,y Field frame End Type Type DOOR Field x,y End Type Type PLATFORM Field x,y End Type Type BACKGROUND Field x,y Field image End Type h.HENRY = New HENRY h\x = 500 h\y = 200 h\frame = 0 p.PLATFORM = New PLATFORM p\x = -1500 p\y = 500 d.DOOR = New DOOR d\x = 500 d\y = 200 b.BACKGROUND = New BACKGROUND b\x = 150 b\y = 50 b\image = BACKGROUND While Not KeyDown (1) Cls TileImage (b\image,b\x,b\y) ;---------------------------------------------------------------------------------------------------------------------------------------------------------- ;Here is the part I need help with ;----------------------------------------------------------------------------------------------------------------------------------------------------------------- If KeyHit (57) Then ;------ I'd like to cancel this when my character collides with the door h\y = h\y - 600 EndIf If Not KeyHit (57) Then ;------I'd like to also cancel this when my character collides with the door h\y = h\y + 40 EndIf If ImagesCollide (HENRY,h\x,h\y,0,DOOR,d\x,d\y,0) Then ;----- I would like key (57) to be cancelled when this happens ;------ That is, I want to make it so that key (57) can no longer ;-------- be used for jumping after this happens (for now). b\image = BACKGROUND2 EndIf ;-------------------------------------------------------------------------------------------------------------------------------------------------------------------- ;Thanks, this section was all I needed help with for now. ;----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- If KeyDown(205) h\x = h\x + 3 EndIf If KeyDown(203) h\x = h\x - 3 EndIf If ImagesCollide (HENRY, h\x, h\y,0,PLATFORM,(b\x + p\x), p\y,0) Then h\y = 430 EndIf DrawImage (PLATFORM,p\x,p\y) DrawImage (DOOR, d\x,d\y) DrawImage (HENRY,h\x,h\y) Flip Wend Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 Last edited 2011 |
| ||
Why not just add a flag (set to True or False) when jumping is enabled.If(h\jump_active = True) Then If KeyHit (57) Then h\y = h\y - 600 EndIf If Not KeyHit (57) Then h\y = h\y + 40 EndIf EndIf If ImagesCollide (HENRY,h\x,h\y,0,DOOR,d\x,d\y,0) b\image = BACKGROUND2 h\jump_active = False Else h\jump_active = True EndIf Last edited 2011 Last edited 2011 |
| ||
Thanks Yeshu, it worked. |
| ||
No Problem. |