Posted: Sun May 23, 2004 8:34 am Post subject: posted all me pic with game
Hi guys, I am making the asteroid game and I am almost done. I need help to disappear the rock from screen when I shoot with my gun, and also how can I do this by chance if rock hit my plane, then the plan crash and after 2 second, new ship appear. Some one plz help cus this is my first and last assignment in Turing. i post all the pics one more question where do i put background in my game. i am using keyboard not mouse. my friend told me that i have to use function or boolen and i don't know how, you can explain to me or can give me the codes.
here are the codes of my game
[img]
code:
View.Set ("graphics:800;600,offscreenonly")
var shipUpper : int := Pic.FileNew ("gun.jpg")
var bulletUpper : int := Pic.FileNew ("bullet.jpg")
var rock : int := Pic.FileNew ("rock.jpg")
Pic.SetTransparentColour (rock, black)
var shipDown : int := Pic.Rotate (shipUpper, 180, -1, -1) % Rotate for down arrow
var shipLeft : int := Pic.Rotate (shipUpper, 90, -1, -1) % Rotate for left arrow
var shipRight : int := Pic.Rotate (shipUpper, 270, -1, -1) % Rotate for right arrow
var bulletDown : int := Pic.Rotate (bulletUpper, 180, -1, -1)
var bulletLeft : int := Pic.Rotate (bulletUpper, 90, -1, -1)
var bulletRight : int := Pic.Rotate (bulletUpper, 270, -1, -1)
var x1, y1, x2, x3, y4, bulletX, bulletY, score, life, rockX, rockY : int := 0
var keys : array char of boolean % they key currently being pressed
var KEY_SPACEBAR : char := chr (32)
var UP_ARROW : char := chr (200)
var LEFT_ARROW : char := chr (203)
var RIGHT_ARROW : char := chr (205)
var DOWN_ARROW : char := chr (208)
life := 20
rockX := 20
rockY := 700
process rockDropping
loop
Pic.Draw (rock, rockX, rockY, picXor)
View.Update
Pic.Draw (rock, rockX, rockY, picXor)
rockY := rockY - 10
if rockY <= 0 then
randint (rockX, 20, 500)
randint (rockY, 700, 900)
rockY := rockY - 10
end if
end loop
end rockDropping
fork rockDropping
loop
colorback (black)
Input.KeyDown (keys)
if keys (UP_ARROW) then
cls
Pic.Draw (shipUpper, x2 + x3, y1 + y4, picMerge)
y1 := y1 + 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletUpper, x2 + x3 + 34, y1 + y4 + 120 + bulletY, picMerge)
bulletY := bulletY + 10
else
bulletY := 0
end if
elsif keys (LEFT_ARROW) then
cls
Pic.Draw (shipLeft, x2 + x3, y1 + y4, picMerge)
x2 := x2 - 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletLeft, x2 + x3 - 40, y1 + y4 + 35 - bulletX, picMerge)
bulletX := bulletX - 10
else
bulletX := 0
end if
elsif keys (DOWN_ARROW) then
cls
Pic.Draw (shipDown, x2 + x3, y4 + y1, picMerge)
y4 := y4 - 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletDown, x2 + x3 + 34, y1 + y4 - 40 + bulletY, picMerge)
bulletY := bulletY - 7
else
bulletY := 0
end if
elsif keys (RIGHT_ARROW) then
cls
Pic.Draw (shipRight, x3 + x2, y1 + y4, picMerge)
x3 := x3 + 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletRight, x2 + x3 + 131, y1 + y4 + 35 + bulletX, picMerge)
bulletX := bulletX + 10
else
bulletX := 0
end if
end if
Posted: Sun May 23, 2004 10:10 am Post subject: (No subject)
I believe there is a very detailed asteroid game source released when you install turing. You can always look through that. It covers everything, even Frames Per Second if you need it.
snaz
Posted: Mon May 24, 2004 1:07 pm Post subject: done everything just need help to disapear the rock
the game u get from turing it's pretty advance cus it's university level and i can't understand cus i am in grade 10. i done score and everything i just need to dispaer the rokc when the bullet hit the rock
here are the codes
code:
View.Set ("graphics:800;600,offscreenonly")
colorback (black)
var shipUpper : int := Pic.FileNew ("gun3.jpg")
var bulletUpper : int := Pic.FileNew ("bullet.jpg")
var rock : int := Pic.FileNew ("rock.bmp")
var shipDown : int := Pic.Rotate (shipUpper, 180, -1, -1) % Rotate for down arrow
var shipLeft : int := Pic.Rotate (shipUpper, 90, -1, -1) % Rotate for left arrow
var shipRight : int := Pic.Rotate (shipUpper, 270, -1, -1) % Rotate for right arrow
var bulletDown : int := Pic.Rotate (bulletUpper, 180, -1, -1)
var bulletLeft : int := Pic.Rotate (bulletUpper, 90, -1, -1)
var bulletRight : int := Pic.Rotate (bulletUpper, 270, -1, -1)
var x1, y1, x2, x3, y4, bulletX, bulletY, score, life, rockX, rockY : int := 0
var rockDead : boolean := true
var keys : array char of boolean % they key currently being pressed
var KEY_SPACEBAR : char := chr (32)
var UP_ARROW : char := chr (200)
var LEFT_ARROW : char := chr (203)
var RIGHT_ARROW : char := chr (205)
var DOWN_ARROW : char := chr (208)
life := 10
rockY := 700
process rockDropping
loop
if rockDead = true then
Pic.Draw (rock, rockX, rockY, picXor)
for b : 1 .. 20
View.Update
end for
Pic.Draw (rock, rockX, rockY, picXor)
if rockY < 0 then
randint (rockX, 20, 500)
randint (rockY, 700, 900)
score := score - 5
delay (500)
end if
rockY := rockY - 10
elsif rockDead = false then
Pic.Draw (rock, rockX, rockY, picXor)
for b : 1 .. 20
View.Update
end for
Pic.Draw (rock, rockX, rockY, picXor)
if rockY < 0 then
randint (rockX, 20, 500)
randint (rockY, 700, 900)
score := score - 5
delay (500)
end if
rockY := rockY - 10
end if
exit when life = 0
end loop
end rockDropping
fork rockDropping
loop
colorback (black)
Input.KeyDown (keys)
if keys (UP_ARROW) then
cls
Pic.Draw (shipUpper, x2 + x3, y1 + y4, picMerge)
if rockY <= y1 + 10 + y4 and rockX <= x2 + x3 then
end if
y1 := y1 + 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletUpper, x2 + x3 + 34, y1 + y4 + 120 + bulletY, picMerge)
if x2 + x3 + 34 >= rockX and y1 + y4 + 120 + bulletY + 10 >= rockY - 10 then
score := score + 10
rockDead := false
end if
bulletY := bulletY + 10
else
bulletY := 0
end if
elsif keys (LEFT_ARROW) then
cls
Pic.Draw (shipLeft, x2 + x3, y1 + y4, picMerge)
x2 := x2 - 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletLeft, x2 + x3 - 40 - bulletX, y1 + y4 + 35, picMerge)
if x2 + x3 - 40 - bulletX + 10 >= rockX and y1 + y4 + 35 >= rockY - 10 then
score := score + 10
rockDead := false
end if
bulletX := bulletX + 10
else
bulletX := 0
end if
elsif keys (DOWN_ARROW) then
cls
Pic.Draw (shipDown, x2 + x3, y4 + y1, picMerge)
y4 := y4 - 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletDown, x2 + x3 + 34, y1 + y4 - 40 + bulletY, picMerge)
if x2 + x3 + 34 >= rockX and y1 + y4 - 40 + bulletY - 10 >= rockY - 10 then
score := score + 10
rockDead := false
end if
bulletY := bulletY - 10
else
bulletY := 0
end if
elsif keys (RIGHT_ARROW) then
cls
Pic.Draw (shipRight, x3 + x2, y1 + y4, picMerge)
x3 := x3 + 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletRight, x2 + x3 + 131 + bulletX, y1 + y4 + 35, picMerge)
if x2 + x3 + 131 + bulletX + 10 >= rockX and y1 + y4 + 35 >= rockY - 10 then
score := score + 10
rockDead := false
end if
bulletX := bulletX + 10
else
bulletX := 0
end if
end if
if rockX <= x2 + x3 and rockY <= y1 + y4 then
life := life - 1
end if
if score = 100 then
life := life + 1
elsif score = 200 then
life := life + 1
end if
exit when life = 0
locate (33, 87)
color (white)
put score, " : Score"
locate (35, 87)
color (white)
put life, " : Life"
View.Update
end loop
vagyb
Posted: Mon May 24, 2004 1:09 pm Post subject: (No subject)
could u post the pictures again it says they dont exist :S
snaz
Posted: Mon May 24, 2004 3:16 pm Post subject: can't post the pics
i tried to many times but i can't post the pics. i don't know y , pls help me without the pics, i really need help cus i spend me whole weekend try to disapear the rock but i cna't that's y i post here
Dan
Posted: Tue May 25, 2004 2:23 pm Post subject: (No subject)
odd, e-mail me them dan@compsci.ca and i can upload them to this site if you still need help with this.
Computer Science CanadaHelp with programming in C, C++, Java, PHP, Ruby, Turing, VB and more!
snaz
Posted: Wed May 26, 2004 3:02 pm Post subject: posted my pic on website
hi, i upload my pics on this site www.compsci.ca/userfiles/game.zip
now plz some one help and i am not posting my problem again cus i already did.
guruguru
Posted: Wed May 26, 2004 6:44 pm Post subject: (No subject)
code:
if rockDead then
rockY := maxy + rockHeight % above screen
randint (rockX, .., ..)
end if
That works.
Sponsor Sponsor
snaz
Posted: Thu May 27, 2004 5:17 pm Post subject: Can you More specific plz
my problem was how the rock disapear from screen when i shoote with the bullet adn then automatically new rock appear from screen. and plz be more scpecific so i can understand, thanks
guruguru
Posted: Thu May 27, 2004 5:42 pm Post subject: (No subject)
rockY := maxy % above screen
This sets the rock back to the top of the screen. It is gone from the screen and starts agains as if it is a new rock.
randint (rockX, .., ..)
This makes the rock at a random x location as a new rock would. YOu can plug in your own numbers.
Do you have a collision detection set up for the bullet and rock? If not, then I suggest you do so. Test if the bulletY is >= to rockY and if bulletX is in the range of rockX. If so, then it should be easy. When bullet hits rock, rockDead = true, and call the procedure mentioned earlier to renew the rock.
snaz
Posted: Thu May 27, 2004 7:30 pm Post subject: Hope ur idea work
Thanks man i hope ur idea will work and i will post it again if ur idea some how doesn't work.
snaz
Posted: Thu May 27, 2004 9:36 pm Post subject: yo guruguru it doesn't work
i tried to many times but it doesn't work, what should i do?
guruguru
Posted: Thu May 27, 2004 9:50 pm Post subject: (No subject)
What to you mean 'it doesnt work'. It will work if implemented correctly. Post the code portion of your implementation so me and others can see what you are doing wrong and right.
snaz
Posted: Sat May 29, 2004 4:48 pm Post subject: (No subject)
this is my game codes and pic i already poted
code:
View.Set ("graphics:800;600,offscreenonly")
colorback (black)
var shipUpper : int := Pic.FileNew ("gun3.jpg")
var bulletUpper : int := Pic.FileNew ("bullet.jpg")
var rock : int := Pic.FileNew ("rock.bmp")
var shipDown : int := Pic.Rotate (shipUpper, 180, -1, -1) % Rotate for down arrow
var shipLeft : int := Pic.Rotate (shipUpper, 90, -1, -1) % Rotate for left arrow
var shipRight : int := Pic.Rotate (shipUpper, 270, -1, -1) % Rotate for right arrow
var bulletDown : int := Pic.Rotate (bulletUpper, 180, -1, -1)
var bulletLeft : int := Pic.Rotate (bulletUpper, 90, -1, -1)
var bulletRight : int := Pic.Rotate (bulletUpper, 270, -1, -1)
var x1, y1, x2, x3, y4, bulletX, bulletY, score, life, rockX, rockY : int := 0
var rockDead : boolean := true
var keys : array char of boolean % they key currently being pressed
var KEY_SPACEBAR : char := chr (32)
var UP_ARROW : char := chr (200)
var LEFT_ARROW : char := chr (203)
var RIGHT_ARROW : char := chr (205)
var DOWN_ARROW : char := chr (208)
life := 10
rockY := 700
process rockDropping
loop
if rockDead = true then
Pic.Draw (rock, rockX, rockY, picXor)
for b : 1 .. 20
View.Update
end for
Pic.Draw (rock, rockX, rockY, picXor)
if rockY < 0 then
randint (rockX, 20, 500)
randint (rockY, 700, 900)
score := score - 5
delay (500)
end if
rockY := rockY - 10
elsif rockDead = false then
Pic.Draw (rock, rockX, rockY, picXor)
for b : 1 .. 20
View.Update
end for
Pic.Draw (rock, rockX, rockY, picXor)
if rockY < 0 then
randint (rockX, 20, 500)
randint (rockY, 700, 900)
score := score - 5
delay (500)
end if
rockY := rockY - 10
end if
exit when life = 0
end loop
end rockDropping
fork rockDropping
loop
colorback (black)
Input.KeyDown (keys)
if keys (UP_ARROW) then
cls
Pic.Draw (shipUpper, x2 + x3, y1 + y4, picMerge)
if rockY <= y1 + 10 + y4 and rockX <= x2 + x3 then
end if
y1 := y1 + 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletUpper, x2 + x3 + 34, y1 + y4 + 120 + bulletY, picMerge)
if x2 + x3 + 34 >= rockX and y1 + y4 + 120 + bulletY + 10 >= rockY - 10 then
score := score + 10
rockDead := false
end if
bulletY := bulletY + 10
else
bulletY := 0
end if
elsif keys (LEFT_ARROW) then
cls
Pic.Draw (shipLeft, x2 + x3, y1 + y4, picMerge)
x2 := x2 - 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletLeft, x2 + x3 - 40 - bulletX, y1 + y4 + 35, picMerge)
if x2 + x3 - 40 - bulletX + 10 >= rockX and y1 + y4 + 35 >= rockY - 10 then
score := score + 10
rockDead := false
end if
bulletX := bulletX + 10
else
bulletX := 0
end if
elsif keys (DOWN_ARROW) then
cls
Pic.Draw (shipDown, x2 + x3, y4 + y1, picMerge)
y4 := y4 - 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletDown, x2 + x3 + 34, y1 + y4 - 40 + bulletY, picMerge)
if x2 + x3 + 34 >= rockX and y1 + y4 - 40 + bulletY - 10 >= rockY - 10 then
score := score + 10
rockDead := false
end if
bulletY := bulletY - 10
else
bulletY := 0
end if
elsif keys (RIGHT_ARROW) then
cls
Pic.Draw (shipRight, x3 + x2, y1 + y4, picMerge)
x3 := x3 + 10
if keys (KEY_SPACEBAR) then
Pic.Draw (bulletRight, x2 + x3 + 131 + bulletX, y1 + y4 + 35, picMerge)
if x2 + x3 + 131 + bulletX + 10 >= rockX and y1 + y4 + 35 >= rockY - 10 then
score := score + 10
rockDead := false
end if
bulletX := bulletX + 10
else
bulletX := 0
end if
end if
if rockX <= x2 + x3 and rockY <= y1 + y4 then
life := life - 1
end if
if score = 100 then
life := life + 1
elsif score = 200 then
life := life + 1
end if
exit when life = 0
locate (33, 87)
color (white)
put score, " : Score"
locate (35, 87)
color (white)
put life, " : Life"
View.Update
end loop
guruguru
Posted: Sat May 29, 2004 6:50 pm Post subject: (No subject)
Quote:
code:
if rockDead = true then
Pic.Draw (rock, rockX, rockY, picXor)
for b : 1 .. 20
View.Update
end for
Pic.Draw (rock, rockX, rockY, picXor)
if rockY < 0 then
randint (rockX, 20, 500)
randint (rockY, 700, 900)
score := score - 5
delay (500)
end if
rockY := rockY - 10
elsif rockDead = false then
Pic.Draw (rock, rockX, rockY, picXor)
for b : 1 .. 20
View.Update
end for
Pic.Draw (rock, rockX, rockY, picXor)
if rockY < 0 then
randint (rockX, 20, 500)
randint (rockY, 700, 900)
score := score - 5
delay (500)
end if
rockY := rockY - 10
end if
Umm... what is up with this? They are the exact same . And some more things regarding them... please don't take offence these are tips to improve your program.
1)
code:
for b : 1 .. 20
View.Update
end for
This is pointless. You update the screen 20x in a row. You should delete this and View.Update only at the end of the loop.
2) You should draw the picture only once in the whole loop. And that should be just before you call View.Update.
3)
code:
if rockY < 0 then
This is unncessary. We already know that the rock is dead so it should be reset no matter what. Delete this if and end if, but not the content.
4)
code:
score := score - 5
When you shoot the rock you should gain points. And a short form is this:
code:
score += 5
5)
code:
rockY := rockY - 10
This should happen no matter what and should be called just before you draw the picutre.
To sum up, the first if statement should test to see if rock is dead or the rock is at the bottom of the screen because the same things should happen.
code:
if rockDead = true then
%Pic.Draw (rock, rockX, rockY, picXor) not needed here
/*for b : 1 .. 20
View.Update completely unecesary
end for */
%Pic.Draw (rock, rockX, rockY, picXor) not need here
%if rockY < 0 then this is only for second part of if
randint (rockX, 20, 500)
randint (rockY, 700, 900) good- assigs new values
%score := score - 5 should be score += 5
delay (500) w/e suits you
%end if
%rockY := rockY - 10 not here
elsif rockY < 0 then you already know its not dead
/*Pic.Draw (rock, rockX, rockY, picXor)
for b : 1 .. 20
View.Update
end for
Pic.Draw (rock, rockX, rockY, picXor)
if rockY < 0 then */
randint (rockX, 20, 500)
randint (rockY, 700, 900)
score := score - 5 thse 4 lines are right on
delay (500)
end if
%rockY := rockY - 10 not here
end if
rockY := rockY - 10 % should be here
Pic.Draw (rock, rockX, rockY, picXor) % now we draw with new coor
View.Update % and now we draw
And the new code...
code:
if rockDead = true or rockY < 0 then
randint (rockX, 20, 500)
randint (rockY, 700, 900)
end if