Posted: Fri May 23, 2003 2:03 pm Post subject: Need help with my Tank Game
I having trouble trying to get my tank to move while shooting.
code:
setscreen ("graphics:800;500")
setscreen ("nocursor")
var Bullet: int
var Game : int
var Tank : int
var x : int := 0
var reply : string (1)
var Tank2 : int
Game := Pic.FileNew ("Game2.bmp") %Locates the picture
Pic.Draw (Game, 0, 0, 2) %Draws the picture
Tank := Pic.FileNew ("Tank.bmp") %Locates the picture
Pic.Draw (Tank, 320, -230, 2) %Draws the picture
Bullet := Pic.FileNew ("bullet.bmp") %Locates the picture
Tank2 := Pic.FileNew ("Tank2.bmp") %Locates the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
loop
getch (reply)
if reply = "d" then
Pic.Draw (Game, 0, 0, 2)
Pic.Draw (Tank, 320 + x, -230, 2) %Draws the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
x := x + 12
end if
if reply = "a" then
Pic.Draw (Game, 0, 0, 2)
Pic.Draw (Tank, 320 + x, -230, 2) %Draws the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
x:= x - 12
end if
if reply = "x" then
for i: 1..400
Pic.Draw (Bullet, 80 + x, -170 + i, 2) %Draws the picture
end for
end if
if x = 0 then
Pic.Draw (Game, 0, 0, 2)
Pic.Draw (Tank, 320 + x, -230, 2) %Draws the picture
end if
end loop
By the way a is to move left, d is to move right and x is to fire.
Sponsor Sponsor
Asok
Posted: Fri May 23, 2003 3:23 pm Post subject: (No subject)
rule of thumb. ALWAYS upload your external bitmaps.
just zip them up and attach them so we can actually run this.
Tony
Posted: Fri May 23, 2003 4:25 pm Post subject: (No subject)
if might help if you'd use Input.KeyDown instead... read tutorial... everybody who knows how to use that recomments it over getch...
now, you should make a separate procedure for the bullet that will move it along its trajectory. Then set a flag variable in the main loop so that the procedure keeps on getting called to move the bullet while its on screen. This way it moves bullet 1 spot, then returns to tank controls to allow you to move it as well..
Posted: Fri May 23, 2003 4:51 pm Post subject: (No subject)
How would i use Input.KeyRight in my code? Can you give me an example please.
Dragoon
Posted: Fri May 23, 2003 6:03 pm Post subject: (No subject)
Okay , i got everything to work except for the Bullet, i made a procedure and now how do i have it so the bullet moves while the tank moves too?
Tony
Posted: Fri May 23, 2003 7:17 pm Post subject: (No subject)
structure it like this:
procedure moveBullet
bulletX += movementX
bulletY += movementY
%maye some other stuff like check if it hit something or what not
%reset bulletFlag back to flase once bullet is done moving
end moveBullet
%main loop
loop
input.ketdown stuff
if chars('f') then
%or whatever button you want to fire with
bulletFlag = true
end if
Posted: Sat May 24, 2003 6:52 am Post subject: (No subject)
Below is the code i have right now.
Dragoon
Posted: Sat May 24, 2003 7:28 am Post subject: (No subject)
Okay, iam having trouble understanding what you just put, what do i have to do with the bullety and x stuff in the procedure? Also do i have my Draw Bullet in the right spot?
code:
setscreen ("graphics:800;500")
setscreen ("nocursor")
var Bullet : int
var Game : int
var Tank : int
var x : int := 0
var reply : string (1)
var Tank2 : int
var bulletX : int
var movementX : int
var movementY : int
var bulletY : int
var bulletflag : boolean := true
Game := Pic.FileNew ("Game2.bmp") %Locates the picture
Pic.Draw (Game, 0, 0, 2) %Draws the picture
Tank := Pic.FileNew ("Tank.bmp") %Locates the picture
Pic.Draw (Tank, 320, -230, 2) %Draws the picture
Bullet := Pic.FileNew ("bullet.bmp") %Locates the picture
Tank2 := Pic.FileNew ("Tank2.bmp") %Locates the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_ENTER) then
bulletflag := true
end if
if bulletflag then
moveBullet
end if
if chars (KEY_RIGHT_ARROW) then
Pic.Draw (Game, 0, 0, 2)
Pic.Draw (Tank, 320 + x, -230, 2) %Draws the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
x := x + 12
end if
if chars (KEY_LEFT_ARROW) then
Pic.Draw (Game, 0, 0, 2)
Pic.Draw (Tank, 320 + x, -230, 2) %Draws the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
x := x - 12
end if
end loop
Posted: Sat May 24, 2003 5:13 pm Post subject: (No subject)
Okay, i understand it now, but whenever i start my program the bullet fires. This is what i have.
code:
setscreen ("graphics:800;500")
setscreen ("nocursor")
var Bullet : int
var Game : int
var Tank : int
var x : int := 0
var y : int := 1
var reply : string (1)
var Tank2 : int
var bulletX : int := 80
var movementX : int := 0
var movementY : int := 1
var bulletY : int := -170
var bulletflag : boolean := true
Game := Pic.FileNew ("Game2.bmp") %Locates the picture
Pic.Draw (Game, 0, 0, 2) %Draws the picture
Tank := Pic.FileNew ("Tank.bmp") %Locates the picture
Pic.Draw (Tank, 320, -230, 2) %Draws the picture
Bullet := Pic.FileNew ("bullet.bmp") %Locates the picture
Tank2 := Pic.FileNew ("Tank2.bmp") %Locates the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
var chars : array char of boolean
loop
Input.KeyDown (chars)
if chars (KEY_ENTER) then
bulletflag := true
end if
if bulletflag = true then
moveBullet
end if
if chars (KEY_RIGHT_ARROW) then
Pic.Draw (Game, 0, 0, 2)
Pic.Draw (Tank, 320 + x, -230, 2) %Draws the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
x := x + 12
end if
if chars (KEY_LEFT_ARROW) then
Pic.Draw (Game, 0, 0, 2)
Pic.Draw (Tank, 320 + x, -230, 2) %Draws the picture
Pic.Draw (Tank2, 240, 220, 2) %Draws the picture
x := x - 12
end if
end loop
Tony
Posted: Sat May 24, 2003 8:03 pm Post subject: (No subject)
thats cuz you initialize your bulletFlag variable to true when you declear it. Make it false instead.