gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
I have a few questions I have got my program working well the move ment system but if I press space at the right time it keeps going rather than dropping down and reversing direction also now my bullets don't appear here is my code it is the full code so hopefully its not to long
;sets the screen size Graphics 800,600 ;sets the constants Const tank$ = "<*!*>" Const enemy$ = "<O> " Const bullet$ = "!" Const enemybullet$ = "o" ;the tank ;all the variables for the tank Type tank Field x,y Field tankstring$ End Type ;the bullet ;all the variables for the bullet Type bullet Field x,y Field bulletstring$ Field bullet Field move End Type Type enemy Field x,y Field hitcounter Field dx End Type Global ship.enemy = New enemy ship\x = 100 ship\y = 0 ship\dx = 1 Global player.tank = New tank Global playerbullet.bullet = New bullet ;starting position for tank player\x = 400 player\y = 550 player\tankstring$ = tank$ ;starting position for bullet playerbullet\bulletstring$ = bullet$ playerbullet\x = player\x + 16 playerbullet\y = player\y ;keeps the bullet in the right spot and stops it from shooting to many times playerbullet\bullet = 1 playerbullet\move = 0 ;the entire game is stored in this loop Dim alien$(3, 24) While Not KeyDown(1) Cls testinput() moveenemy() enemies() Text player\x, player\y, player\tankstring$ playerbullet\bullet = 1 Flip Wend Function testinput() If KeyHit(57) moveenemy() updatebullet() Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ EndIf If KeyDown(203) ;moves the tank left player\x = player\x - 3 If player\x <= 0;stops the tank from going off screen player\x = 10 EndIf If playerbullet\move = 0 Then playerbullet\x = playerbullet\x - 3;moves the bullet left with the tank EndIf EndIf ;If player presses right, move him right. If KeyDown(205) ;moves the tank right;;;;;; player\x = player\x + 3;;;; If player\x >= 800;stops the tank from going off screen player\x = 790 EndIf If playerbullet\move = 0 Then playerbullet\x = playerbullet\x + 3; moves the bullet right with the tank EndIf EndIf End Function Function updatebullet() ;move the bullet While playerbullet\bullet = 1 Cls testinput() enemies() moveenemy() playerbullet\move = 1 If playerbullet\bullet = 1 Then Text player\x, player\y, player\tankstring$;prints the tank on the screen Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$;prints the bullet playerbullet\y = playerbullet\y - 3 If playerbullet\y <= 0 Then;determines whether the bullet goes off the screen ;sets the bullet back to the starting position playerbullet\y = player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; playerbullet\bullet = 0;determines whether the bullet has been shot playerbullet\move = 0;determines whether to move the bullet with the tank EndIf Flip EndIf Wend End Function Function FindChar$(i) Locate ship\x,ship\y If i = 0 Locate ship\x,ship\y Return enemy$ Else If i = 1 Locate ship\x,ship\y Return enemy$ Else If i = 2 Locate ship\x,ship\y Return enemy$ EndIf End Function Function moveenemy() Repeat Cls enemies() testinput() If ship\dx = -2 And ship\x <= 100 Then ship\dx = 2 EndIf ship\x = ship\x + ship\dx Text player\x, player\y, player\tankstring$ Flip Until ship\x >= 200 Flip If ship\x >= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf Flip Repeat Cls enemies() testinput() ship\x = ship\x + ship\dx Text player\x, player\y, player\tankstring$ Flip Until ship\x <= 100 If ship\x <= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf Flip End Function ;makes the enemies appear on screen Function enemies() Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Locate ship\x,ship\y alien$(rows,columns) = FindChar$(rows) Locate ship\x,ship\y Next Locate ship\x,ship\y Next Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Write alien$(rows,columns) Next Print "" Next Locate ship\x,ship\y + 12 For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Locate ship\x,ship\y alien$(rows,columns) = FindChar$(rows) Locate ship\x,ship\y Next Locate ship\x,ship\y Next Locate ship\x,ship\y For rows = 0 To 2 Locate ship\x,ship\y + 12 For columns = 0 To 14 Write alien$(rows,columns) Next Print "" NextEnd Function |
|
gaurdianAQ
Member
Posts: 106
From:
Registered: 01-15-2007
|
ok I made it so it does not continue but now it reverses direct without dropping down but only if you hit the space bar at the right time why is this here is the new code ;sets the screen size Graphics 800,600 ;sets the constants Const tank$ = "<*!*>" Const enemy$ = "<O> " Const bullet$ = "!" Const enemybullet$ = "o" ;the tank ;all the variables for the tank Type tank Field x,y Field tankstring$ End Type ;the bullet ;all the variables for the bullet Type bullet Field x,y Field bulletstring$ Field bullet Field move End Type Type enemy Field x,y Field hitcounter Field dx End Type Global ship.enemy = New enemy ship\x = 100 ship\y = 0 ship\dx = 1 Global player.tank = New tank Global playerbullet.bullet = New bullet ;starting position for tank player\x = 400 player\y = 550 player\tankstring$ = tank$ ;starting position for bullet playerbullet\bulletstring$ = bullet$ playerbullet\x = player\x + 16 playerbullet\y = player\y ;keeps the bullet in the right spot and stops it from shooting to many times playerbullet\bullet = 1 playerbullet\move = 0 ;the entire game is stored in this loop Dim alien$(3, 24) While Not KeyDown(1) Cls testinput() moveenemy() enemies() Text player\x, player\y, player\tankstring$ playerbullet\bullet = 1 Flip Wend Function testinput() If KeyHit(57) moveenemy() updatebullet() Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$ EndIf If KeyDown(203) ;moves the tank left player\x = player\x - 3 If player\x <= 0;stops the tank from going off screen player\x = 10 EndIf If playerbullet\move = 0 Then playerbullet\x = playerbullet\x - 3;moves the bullet left with the tank EndIf EndIf ;If player presses right, move him right. If KeyDown(205) ;moves the tank right;;;;;; player\x = player\x + 3;;;; If player\x >= 800;stops the tank from going off screen player\x = 790 EndIf If playerbullet\move = 0 Then playerbullet\x = playerbullet\x + 3; moves the bullet right with the tank EndIf EndIf End Function Function updatebullet() ;move the bullet While playerbullet\bullet = 1 Cls testinput() enemies() moveenemy() playerbullet\move = 1 If playerbullet\bullet = 1 Then Text player\x, player\y, player\tankstring$;prints the tank on the screen Text playerbullet\x, playerbullet\y, playerbullet\bulletstring$;prints the bullet playerbullet\y = playerbullet\y - 3 If playerbullet\y <= 0 Then;determines whether the bullet goes off the screen ;sets the bullet back to the starting position playerbullet\y = player\y;;;;;;;;;;;;;;;;;;;;; playerbullet\x = player\x + 16;;;;;;;;;;;;;;;; playerbullet\bullet = 0;determines whether the bullet has been shot playerbullet\move = 0;determines whether to move the bullet with the tank EndIf Flip EndIf Wend End Function Function FindChar$(i) Locate ship\x,ship\y If i = 0 Locate ship\x,ship\y Return enemy$ Else If i = 1 Locate ship\x,ship\y Return enemy$ Else If i = 2 Locate ship\x,ship\y Return enemy$ EndIf End Function Function moveenemy() Repeat Cls enemies() testinput() ship\x = ship\x + ship\dx If ship\dx = -1 And ship\x <= 100 Then ship\dx = 1 EndIf Text player\x, player\y, player\tankstring$ Flip Until ship\x >= 200 Flip If ship\x >= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf If ship\x >= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf Flip Repeat Cls enemies() testinput() ship\x = ship\x + ship\dx Text player\x, player\y, player\tankstring$ Flip Until ship\x <= 100 If ship\x <= 100 Then ship\y = ship\y + 12 ship\dx = 1 Flip EndIf If ship\x <= 200 Then ship\y = ship\y + 12 ship\dx = -1 Flip EndIf Flip End Function ;makes the enemies appear on screen Function enemies() Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Locate ship\x,ship\y alien$(rows,columns) = FindChar$(rows) Locate ship\x,ship\y Next Locate ship\x,ship\y Next Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Write alien$(rows,columns) Next Print "" Next Locate ship\x,ship\y + 12 For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Locate ship\x,ship\y alien$(rows,columns) = FindChar$(rows) Locate ship\x,ship\y Next Locate ship\x,ship\y Next Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y + 12 For columns = 0 To 14 Write alien$(rows,columns) Next Print "" Next For rows = 0 To 0 Locate ship\x,ship\y For columns = 0 To 14 Locate ship\x,ship\y alien$(rows,columns) = FindChar$(rows) Locate ship\x,ship\y Next Locate ship\x,ship\y Next Locate ship\x,ship\y For rows = 0 To 0 Locate ship\x,ship\y + 24 For columns = 0 To 14 Write alien$(rows,columns) Next Print "" NextEnd Function |
|