Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Megatokyoguy




PostPosted: Mon May 28, 2007 8:59 am   Post subject: Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

Howdy.
Me and a few friends are working on a Turing game (something like asteroids) for a group project. Personally, I can do the technical stuff - put, get, multiple selection - that kinda stuff for like an accounting program or w/e. I am graphically and somewhat technically challenged.

We haven't completely finished it or even debugged it or anything yet, but we were hoping that we could get some advice on adding asteroids (which we originally had) some gravity, and better projectiles.

We'll probably change the pictures later on (we don't have much time left).

Any advice or help with regards to the gravity, projectiles, and asteroids - destroying them or being destroyed by them etc. would be GREATLY appreciated.

Thanks alot guys!
We're counting on you Mr. Green Razz Wink


code:
setscreen ("graphics:800,600")
colourback (black)
cls

%-----------------------------------------------------------------------------
%Variables--------------------------------------------------------------------
%-----------------------------------------------------------------------------

%These variables are used for holding the ship's images
var ship_image : int
var ship_image_rot : array 0 .. 180 of int

%These variables are used as the ship's coordinates
var ship_x, ship_y : int := 300

%These variables are used for moving the ship and drawing it on an angle
var ship_move, ship_angle : int := 0




%These variables are used for holding the 2nd ship's images
var ship2_image : int
var ship2_image_rot : array 0 .. 180 of int

%These variables are used as the ship's coordinates
var ship2_x, ship2_y : int := 300

%These variables are used for moving the ship and drawing it on an angle
var ship2_move, ship2_angle : int := 0




%These variables are used to hold the bullet's images
var bullet_image : int
var bullet_image_rot : array 0 .. 180 of int

%These variables are used as the bullet's coordinates
var bullet_x, bullet_y : int := 0
var bullet_x_last, bullet_y_last, bullet_next_co : int := 1
var bullet_x_current, bullet_y_current : int := 0

%These variables are used as the bullet's angle
var bullet_angle : int := 1

%These variables are used to control the bullet's draw
var bullet_keydown, bullet_fly : int := 0




%These variables are used to hold the bullet's images
var bullet2_image : int
var bullet2_image_rot : array 0 .. 180 of int

%These variables are used as the bullet's coordinates
var bullet2_x, bullet2_y : int := 0
var bullet2_x_last, bullet2_y_last, bullet2_next_co : int := 1
var bullet2_x_current, bullet2_y_current : int := 0

%These variables are used as the bullet's angle
var bullet2_angle : int := 1

%These variables are used to control the bullet's draw
var bullet2_keydown, bullet2_fly : int := 0





%These variables are used for getting keyboard input
var key : array char of boolean
var key2 : array char of boolean
const UP_ARROW : char := chr (200)
const RIGHT_ARROW : char := chr (205)
const LEFT_ARROW : char := chr (203)
const SPACE : char := chr (32)
const W : char := "w"
const A : char := "a"
const D : char := "d"
const KEY_0 : char := "0"

%-----------------------------------------------------------------------------
%Loading----------------------------------------------------------------------
%-----------------------------------------------------------------------------

%This procedure creates the images of the ship
procedure make_ship_images
ship_image := Pic.FileNew ("ship.bmp")
for counter : 0 .. 180
ship_image_rot (counter) := Pic.Rotate (ship_image, counter * 2, 64, 64)
end for
end make_ship_images

%This procedure creates the images of the 2nd ship
procedure make_ship2_images
ship2_image := Pic.FileNew ("ship2.bmp")
for counter : 0 .. 180
ship2_image_rot (counter) := Pic.Rotate (ship2_image, counter * 2, 64, 64)
end for
end make_ship2_images


%This procedure creates the images of the bullet
procedure make_bullet_images
bullet_image := Pic.FileNew ("bullet.bmp")
for counter : 0 .. 180
bullet_image_rot (counter) := Pic.Rotate (bullet_image, counter * 2, 32, 32)
end for
end make_bullet_images

%-----------------------------------------------------------------------------
%Draw 1 Frame-----------------------------------------------------------------
%-----------------------------------------------------------------------------

procedure make_frame
Pic.Draw (ship_image_rot (ship_angle), ship_x, ship_y, picMerge)
Pic.Draw (ship2_image_rot (ship2_angle), ship2_x, ship2_y, picMerge)

if bullet_fly = 1 then
Pic.Draw (bullet_image_rot (bullet_angle), bullet_x, bullet_y, picMerge)
end if

if bullet2_fly = 1 then
Pic.Draw (bullet_image_rot (bullet2_angle), bullet2_x, bullet2_y, picMerge)
end if

bullet_keydown := 0
bullet2_keydown := 0

delay (16)
end make_frame



%-----------------------------------------------------------------------------
%Calculate 2nd Bullets's next coordinates and rotation----------------------------
%-----------------------------------------------------------------------------

procedure bullet2_next
if bullet2_fly = 1 then
bullet2_x := bullet2_x + (10 * cosd (bullet2_angle * 2 + 90) div 1)
bullet2_y := bullet2_y + (10 * sind (bullet2_angle * 2 + 90) div 1)
 if bullet2_x < -64 or bullet2_x > 864 or bullet2_y < -64 or bullet2_y > 664 then
 bullet2_x := ship2_x
 bullet2_y := ship2_y
 bullet2_fly := 0
 end if
end if

if bullet2_keydown = 1 and bullet2_fly = 0 then
bullet2_angle := ship2_angle
bullet2_x := ship2_x
bullet2_y := ship2_y
bullet2_fly := 1
end if

make_frame

end bullet2_next



%-----------------------------------------------------------------------------
%Calculate Bullets's next coordinates and rotation----------------------------
%-----------------------------------------------------------------------------

procedure bullet_next
if bullet_fly = 1 then
bullet_x := bullet_x + (10 * cosd (bullet_angle * 2 + 90) div 1)
bullet_y := bullet_y + (10 * sind (bullet_angle * 2 + 90) div 1)
 if bullet_x < -64 or bullet_x > 864 or bullet_y < -64 or bullet_y > 664 then
 bullet_x := ship_x
 bullet_y := ship_y
 bullet_fly := 0
 end if
end if

if bullet_keydown = 1 and bullet_fly = 0 then
bullet_angle := ship_angle
bullet_x := ship_x
bullet_y := ship_y
bullet_fly := 1
end if

bullet2_next

end bullet_next



%-----------------------------------------------------------------------------
%Calculate 2nd Ship's next coordinates and rotation-------------------------------
%-----------------------------------------------------------------------------

procedure ship2_next


if ship2_move = 1 then
   ship2_x := ship2_x + (10 * cosd (ship2_angle * 2 + 90) div 2)
   ship2_y := ship2_y + (10 * sind (ship2_angle * 2 + 90) div 2)
ship2_angle := ship2_angle - 1
   if ship2_angle <= 0 then
   ship2_angle := 180
   end if
   
elsif ship2_move = 2 then
   ship2_x := ship2_x + (10 * cosd (ship2_angle * 2 + 90) div 2)
   ship2_y := ship2_y + (10 * sind (ship2_angle * 2 + 90) div 2)
   ship2_angle := ship2_angle + 1
   if ship2_angle = 180 then
   ship2_angle := 0
   end if
   
elsif ship2_move = 3 then
   ship2_x := ship2_x + (10 * cosd (ship2_angle * 2 + 90) div 2)
   ship2_y := ship2_y + (10 * sind (ship2_angle * 2 + 90) div 2)
   
elsif ship2_move = 4 then
ship2_angle := ship2_angle - 1
   if ship2_angle <= 0 then
   ship2_angle := 180
   end if
   
elsif ship2_move = 5 then
ship2_angle := ship2_angle + 1
   if ship2_angle = 180 then
   ship2_angle := 0
   end if
end if

ship2_move := 0

bullet_next

end ship2_next



%-----------------------------------------------------------------------------
%Calculate Ship's next coordinates and rotation-------------------------------
%-----------------------------------------------------------------------------

procedure ship_next


if ship_move = 1 then
   ship_x := ship_x + (10 * cosd (ship_angle * 2 + 90) div 2)
   ship_y := ship_y + (10 * sind (ship_angle * 2 + 90) div 2)
ship_angle := ship_angle - 1
   if ship_angle <= 0 then
   ship_angle := 180
   end if
   
elsif ship_move = 2 then
   ship_x := ship_x + (10 * cosd (ship_angle * 2 + 90) div 2)
   ship_y := ship_y + (10 * sind (ship_angle * 2 + 90) div 2)
   ship_angle := ship_angle + 1
   if ship_angle = 180 then
   ship_angle := 0
   end if
   
elsif ship_move = 3 then
   ship_x := ship_x + (10 * cosd (ship_angle * 2 + 90) div 2)
   ship_y := ship_y + (10 * sind (ship_angle * 2 + 90) div 2)
   
elsif ship_move = 4 then
ship_angle := ship_angle - 1
   if ship_angle <= 0 then
   ship_angle := 180
   end if
   
elsif ship_move = 5 then
ship_angle := ship_angle + 1
   if ship_angle = 180 then
   ship_angle := 0
   end if
end if

ship_move := 0

ship2_next

end ship_next


%-----------------------------------------------------------------------------
%Get Keyboard Input ----------------------------------------------------------
%-----------------------------------------------------------------------------



procedure key_input

%Ship 1
loop
Input.KeyDown (key)
if key (UP_ARROW) and key (RIGHT_ARROW) then
ship_move := 1
elsif key (UP_ARROW) and key (LEFT_ARROW) then
ship_move := 2
elsif key (UP_ARROW) then
ship_move := 3
elsif key (RIGHT_ARROW) then
ship_move := 4
elsif key (LEFT_ARROW) then
ship_move := 5
end if

if key (KEY_0) and bullet_fly = 0 then
bullet_keydown := 1
end if

%Ship 2
Input.KeyDown (key2)
if key2 (W) and key2 (D) then
ship2_move := 1
elsif key2(W) and key2 (A) then
ship2_move := 2
elsif key2 (W) then
ship2_move := 3
elsif key2 (D) then
ship2_move := 4
elsif key2 (A) then
ship2_move := 5
end if

if key2 (SPACE) and bullet2_fly = 0 then
bullet2_keydown := 1
end if

ship_next

end loop

end key_input

make_ship_images
make_ship2_images
make_bullet_images
key_input


That's all we got so far. If it was excruciatingly painful to read, blame my group mate Razz



Asteroids Project.zip
 Description:
The game we've made. help?

Download
 Filename:  Asteroids Project.zip
 Filesize:  2.86 KB
 Downloaded:  107 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
rollerdude




PostPosted: Mon May 28, 2007 9:19 am   Post subject: Re: Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

first... can i ask, what is the point of posting the file, it you have the code written out just above...

second, i would recommend going into ur turing directory and looking at the space game example (requires turing 4.0.5... or something like that, 3.1.1 doesn't come with it)

third, i hope this helps, and i hope to see ur game when its done!
Megatokyoguy




PostPosted: Wed May 30, 2007 8:33 am   Post subject: RE:Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

0_o

I put the file there so taht you can actually run the program with the proper pictures...

And yes, I already know about that. But for this ISP we thought that that would be a bit too much like cheating.

We needed to add projectiles etc. so it was complicated. But thansk anyways

-Team Dolphin

p.s.
We named the project Codename: Dolphin
CodeMonkey2000




PostPosted: Wed May 30, 2007 11:10 am   Post subject: RE:Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

Collision for asteroids is easy, imagine a circle around your ship, and a circle around the asteroid. The ship's circle cannot enter the asteroid's circle, or else there will be a collision. To implement this into code, take the center point of the circle around the ship, and the center point of the circle around the asteroid. Now find the distance between these to points. To do that use: sqrt((sx-ax)**2+(sy-ay)**2); where sx and sy are the center points of the circle around the ship and ax,ay are the center points of the circle around the asteroid. Now if the distance is more than the sum of the radii (of the circle around the ship and the circle around the asteroid) then a collision has occurred.
Megatokyoguy




PostPosted: Mon Jun 04, 2007 9:06 am   Post subject: RE:Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

Thanks CodeMonkey!
But how do we get the asteroids into the program in the first place?

We have also made it so that the ship appears on the other side once it gets to the end of the screen.

Our projectiles are working better....
We also need the gravity so that the ships drift around after using the "gas" Razz

Thanks for checking in!
Megatokyoguy




PostPosted: Mon Jun 04, 2007 9:08 am   Post subject: Re: Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

code:
View.Set ("graphics:800,600")
colourback (black)
cls

%-----------------------------------------------------------------------------
%Variables--------------------------------------------------------------------
%-----------------------------------------------------------------------------


%These variables are used for holding the ship's images
var ship_image : int
var ship_image_rot : array 0 .. 180 of int

%These variables are used as the ship's coordinates
var ship_x : int := 700
var ship_y : int := 0

%These variables are used for moving the ship and drawing it on an angle
var ship_move, ship_angle : int := 0

%Holds the ship's health value
var ship_health : int := 100




%These variables are used for holding the 2nd ship's images
var ship2_image : int
var ship2_image_rot : array 0 .. 180 of int

%These variables are used as the ship's coordinates
var ship2_x : int := 0
var ship2_y : int := 0

%These variables are used for moving the ship and drawing it on an angle
var ship2_move, ship2_angle : int := 0

%Holds the 2nd ship's health value
var ship2_health : int := 100




%These variables are used to hold the bullet's images
var bullet_image : int
var bullet_image_rot : array 0 .. 180 of int

%These variables are used as the bullet's coordinates
var bullet_x, bullet_y : int := -1
var bullet_x_last, bullet_y_last, bullet_next_co : int := 1
var bullet_x_current, bullet_y_current : int := 0

%These variables are used as the bullet's angle
var bullet_angle : int := 1

%These variables are used to control the bullet's draw
var bullet_keydown, bullet_fly, bullet_true : int := 0




%These variables are used to hold the bullet's images
var bullet2_image : int
var bullet2_image_rot : array 0 .. 180 of int

%These variables are used as the bullet's coordinates
var bullet2_x, bullet2_y : int := -1
var bullet2_x_last, bullet2_y_last, bullet2_next_co : int := 1
var bullet2_x_current, bullet2_y_current : int := 0

%These variables are used as the bullet's angle
var bullet2_angle : int := 1

%These variables are used to control the bullet's draw
var bullet2_keydown, bullet2_fly, bullet2_true : int := 0



%Explosions
var explosion_image, explosion2_image, explosion3_image, explosion4_image, explosion5_image : int
var explosion_true : int := 0
var explosion2_true : int := 0
var explosion_x : int
var explosion_y : int
var explosion2_x : int
var explosion2_y : int
var explosion_count, explosion2_count : int := 0

%These variables are used for getting keyboard input
var key : array char of boolean
var key2 : array char of boolean
const UP_ARROW : char := chr (200)
const RIGHT_ARROW : char := chr (205)
const LEFT_ARROW : char := chr (203)
const SPACE : char := chr (32)
const W : char := "w"
const A : char := "a"
const D : char := "d"
const KEY_0 : char := "0"

%Used pre-load
var systype : int
var title_image : int

%-----------------------------------------------------------------------------
%Loading----------------------------------------------------------------------
%-----------------------------------------------------------------------------

%This procedure creates the images of the ship
procedure make_ship_images
ship_image := Pic.FileNew ("ship.bmp")
for counter : 0 .. 180
ship_image_rot (counter) := Pic.Rotate (ship_image, counter * 2, 49, 49)
end for
end make_ship_images

%This procedure creates the images of the 2nd ship
procedure make_ship2_images
ship2_image := Pic.FileNew ("ship2.bmp")
for counter : 0 .. 180
ship2_image_rot (counter) := Pic.Rotate (ship2_image, counter * 2, 49, 49)
end for
end make_ship2_images


%This procedure creates the images of the bullet
procedure make_bullet_images
bullet_image := Pic.FileNew ("bullet.bmp")
for counter : 0 .. 180
bullet_image_rot (counter) := Pic.Rotate (bullet_image, counter * 2, 32, 32)
end for
end make_bullet_images

procedure make_explosion
explosion_image := Pic.FileNew ("explosion.bmp")
explosion2_image := Pic.FileNew ("explosion2.bmp")
explosion3_image := Pic.FileNew ("explosion3.bmp")
explosion4_image := Pic.FileNew ("explosion4.bmp")
explosion5_image := Pic.FileNew ("explosion5.bmp")
end make_explosion


%-----------------------------------------------------------------------------
%Draw 1 Frame-----------------------------------------------------------------
%-----------------------------------------------------------------------------

procedure make_frame
Pic.Draw (ship_image_rot (ship_angle), ship_x, ship_y, picMerge)
Pic.Draw (ship2_image_rot (ship2_angle), ship2_x, ship2_y, picMerge)

if bullet_fly = 1 then
Pic.Draw (bullet_image_rot (bullet_angle), bullet_x, bullet_y, picMerge)
end if

if bullet2_fly = 1 then
Pic.Draw (bullet_image_rot (bullet2_angle), bullet2_x, bullet2_y, picMerge)
end if

if explosion_true = 1 then
Pic.Draw (explosion_image, explosion_x, explosion_y, picMerge)
explosion_true := 0
bullet_fly := 0
explosion_count := 5
bullet_x := -128
bullet_y := -128
elsif explosion_count >= 5 and explosion_count <= 5 then
Pic.Draw (explosion_image, explosion_x, explosion_y, picMerge)
explosion_count := explosion_count + 1
elsif explosion_count >= 5 and explosion_count <= 10 then
Pic.Draw (explosion2_image, explosion_x, explosion_y, picMerge)
explosion_count := explosion_count + 1
elsif explosion_count >= 10 and explosion_count <= 15 then
Pic.Draw (explosion3_image, explosion_x, explosion_y, picMerge)
explosion_count := explosion_count + 1
elsif explosion_count >= 15 and explosion_count <= 20 then
Pic.Draw (explosion4_image, explosion_x, explosion_y, picMerge)
explosion_count := explosion_count + 1
elsif explosion_count >= 20 and explosion_count <= 25 then
Pic.Draw (explosion5_image, explosion_x, explosion_y, picMerge)
explosion_count := explosion_count + 1
elsif explosion_count >= 25 then
explosion_count := 0
bullet_true := 0
end if

if explosion2_true = 1 then
Pic.Draw (explosion_image, explosion2_x, explosion2_y, picMerge)
explosion2_true := 0
explosion2_count := 5
bullet2_fly := 0
bullet2_x := -128
bullet2_y := -128
elsif explosion2_count >= 5 and explosion2_count <= 10 then
Pic.Draw (explosion2_image, explosion2_x, explosion2_y, picMerge)
explosion2_count := explosion2_count + 1
elsif explosion2_count >= 10 and explosion2_count <= 15 then
Pic.Draw (explosion3_image, explosion2_x, explosion2_y, picMerge)
explosion2_count := explosion2_count + 1
elsif explosion2_count >= 15 and explosion2_count <= 20 then
Pic.Draw (explosion4_image, explosion2_x, explosion2_y, picMerge)
explosion2_count := explosion2_count + 1
elsif explosion2_count >= 20 and explosion2_count <= 25 then
Pic.Draw (explosion5_image, explosion2_x, explosion2_y, picMerge)
explosion2_count := explosion2_count + 1
elsif explosion2_count >= 25 then
explosion2_count := 0
bullet2_true := 0
end if



put "Ship 1 health - %", ship_health, "                                                            " ..
put "Ship 2 health - %", ship2_health ..

bullet_keydown := 0
bullet2_keydown := 0

View.Update

delay (systype)
cls
end make_frame

%-----------------------------------------------------------------------------
%Collision Detection----------------------------------------------------------
%-----------------------------------------------------------------------------

procedure collision_detection
if bullet_x >= ship2_x and bullet_x <= ship2_x + 49 and bullet_y >= ship2_y and bullet_y <= ship2_y + 49 then
explosion_x := bullet_x
explosion_y := bullet_y
explosion_true := 1
ship2_health := ship2_health - 10
end if

if bullet2_x >= ship_x and bullet2_x <= ship_x + 49 and bullet2_y >= ship_y and bullet2_y <= ship_y + 49 then
explosion2_x := bullet2_x
explosion2_y := bullet2_y
explosion2_true := 1
ship_health := ship_health - 10
end if

make_frame

end collision_detection


%-----------------------------------------------------------------------------
%Calculate 2nd Bullets's next coordinates and rotation------------------------
%-----------------------------------------------------------------------------

procedure bullet2_next
if bullet2_fly = 1 then
bullet2_x := bullet2_x + (10 * cosd (bullet2_angle * 2 + 90) div 1)
bullet2_y := bullet2_y + (10 * sind (bullet2_angle * 2 + 90) div 1)
 if bullet2_x < -64 or bullet2_x > 864 or bullet2_y < -64 or bullet2_y > 664 then
 bullet2_x := -1
 bullet2_y := -1
 bullet2_fly := 0
 bullet2_true := 0
 end if
end if

if bullet2_keydown = 1 and bullet2_fly = 0 and bullet2_true = 0 then
bullet2_angle := ship2_angle
bullet2_x := ship2_x + 16
bullet2_y := ship2_y + 16
bullet2_fly := 1
bullet2_true := 1
end if

collision_detection

end bullet2_next



%-----------------------------------------------------------------------------
%Calculate Bullets's next coordinates and rotation----------------------------
%-----------------------------------------------------------------------------

procedure bullet_next
if bullet_fly = 1 then
bullet_x := bullet_x + (10 * cosd (bullet_angle * 2 + 90) div 1)
bullet_y := bullet_y + (10 * sind (bullet_angle * 2 + 90) div 1)
 if bullet_x < -64 or bullet_x > 864 or bullet_y < -64 or bullet_y > 664 then
 bullet_x := -1
 bullet_y := -1
 bullet_fly := 0
 bullet_true := 0
 end if
end if

if bullet_keydown = 1 and bullet_fly = 0 and bullet_true = 0 then
bullet_angle := ship_angle
bullet_x := ship_x + 16
bullet_y := ship_y + 16
bullet_fly := 1
bullet_true := 1
end if

bullet2_next

end bullet_next


%-----------------------------------------------------------------------------
%Calculate 2nd Ship's next coordinates and rotation-------------------------------
%-----------------------------------------------------------------------------

procedure ship2_next


if ship2_move = 1 then
   ship2_x := ship2_x + (10 * cosd (ship2_angle * 2 + 90) div 2)
   ship2_y := ship2_y + (10 * sind (ship2_angle * 2 + 90) div 2)
ship2_angle := ship2_angle - 1
   if ship2_angle <= 0 then
   ship2_angle := 180
   end if
   
elsif ship2_move = 2 then
   ship2_x := ship2_x + (10 * cosd (ship2_angle * 2 + 90) div 2)
   ship2_y := ship2_y + (10 * sind (ship2_angle * 2 + 90) div 2)
   ship2_angle := ship2_angle + 1
   if ship2_angle = 180 then
   ship2_angle := 0
   end if
   
elsif ship2_move = 3 then
   ship2_x := ship2_x + (10 * cosd (ship2_angle * 2 + 90) div 2)
   ship2_y := ship2_y + (10 * sind (ship2_angle * 2 + 90) div 2)
   
elsif ship2_move = 4 then
ship2_angle := ship2_angle - 1
   if ship2_angle <= 0 then
   ship2_angle := 180
   end if
   
elsif ship2_move = 5 then
ship2_angle := ship2_angle + 1
   if ship2_angle = 180 then
   ship2_angle := 0
   end if
end if

if ship2_x > 800 then
ship2_x := -100
elsif ship2_x < -100 then
ship2_x := 800
end if

if ship2_y > 600 then
ship2_y := -100
elsif ship2_y < -100 then
ship2_y := 600
end if

ship2_move := 0

bullet_next

end ship2_next



%-----------------------------------------------------------------------------
%Calculate Ship's next coordinates and rotation-------------------------------
%-----------------------------------------------------------------------------

procedure ship_next


if ship_move = 1 then
   ship_x := ship_x + (10 * cosd (ship_angle * 2 + 90) div 2)
   ship_y := ship_y + (10 * sind (ship_angle * 2 + 90) div 2)
ship_angle := ship_angle - 1
   if ship_angle <= 0 then
   ship_angle := 180
   end if
   
elsif ship_move = 2 then
   ship_x := ship_x + (10 * cosd (ship_angle * 2 + 90) div 2)
   ship_y := ship_y + (10 * sind (ship_angle * 2 + 90) div 2)
   ship_angle := ship_angle + 1
   if ship_angle = 180 then
   ship_angle := 0
   end if
   
elsif ship_move = 3 then
   ship_x := ship_x + (10 * cosd (ship_angle * 2 + 90) div 2)
   ship_y := ship_y + (10 * sind (ship_angle * 2 + 90) div 2)
   
elsif ship_move = 4 then
ship_angle := ship_angle - 1
   if ship_angle <= 0 then
   ship_angle := 180
   end if
   
elsif ship_move = 5 then
ship_angle := ship_angle + 1
   if ship_angle = 180 then
   ship_angle := 0
   end if
end if

if ship_x > 800 then
ship_x := -100
elsif ship_x < -100 then
ship_x := 800
end if

if ship_y > 600 then
ship_y := -100
elsif ship_y < -100 then
ship_y := 600
end if

ship_move := 0

ship2_next

end ship_next


%-----------------------------------------------------------------------------
%Get Keyboard Input ----------------------------------------------------------
%-----------------------------------------------------------------------------



procedure key_input

%Ship 1
loop
Input.KeyDown (key)
if key (UP_ARROW) and key (RIGHT_ARROW) then
ship_move := 1
elsif key (UP_ARROW) and key (LEFT_ARROW) then
ship_move := 2
elsif key (UP_ARROW) then
ship_move := 3
elsif key (RIGHT_ARROW) then
ship_move := 4
elsif key (LEFT_ARROW) then
ship_move := 5
end if

if key (KEY_0) and bullet_fly = 0 then
bullet_keydown := 1
end if

%Ship 2
Input.KeyDown (key2)
if key2 (W) and key2 (D) then
ship2_move := 1
elsif key2(W) and key2 (A) then
ship2_move := 2
elsif key2 (W) then
ship2_move := 3
elsif key2 (D) then
ship2_move := 4
elsif key2 (A) then
ship2_move := 5
end if

if key2 (SPACE) and bullet2_fly = 0 then
bullet2_keydown := 1
end if

ship_next

end loop

end key_input

%-----------------------------------------------------------------------------
%Pre - Load Stuff ----------------------------------------------------------
%-----------------------------------------------------------------------------

title_image := Pic.FileNew ("title.bmp")

loop
Pic.Draw (title_image, 0, 536, picMerge)
colour (white)
locate (6 ,1)
put "What class of system is this running on?"
put ""
put "1. Low - End"
put "2. Mid - Range"
put "3. High - End"
put skip
put ""..
get systype
cls

case systype of
label 1 :
systype := 1
cls
exit
label 2 :
systype := 10
cls
exit
label 3 :
systype := 16
cls
exit
label :
put "Invalid selection."
delay (1000)
cls
end case
end loop   



put "Loading..."..
View.Set ("offscreenonly")
View.Update
make_ship_images
make_ship2_images
make_bullet_images
make_explosion
cls
key_input



Game v6.zip
 Description:
Newest Version

Download
 Filename:  Game v6.zip
 Filesize:  7.65 KB
 Downloaded:  138 Time(s)

CodeMonkey2000




PostPosted: Tue Jun 05, 2007 10:21 pm   Post subject: RE:Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

For asteroids you could use an array of records that keep track of the asteroid's center point, and the x,y of the asteroid Picture. The number of asteroids will be static (it won't change). You should move them in a random direction (select a random angle between 360 and a constant speed).

As for gravity, this will require a bit more work. You need to understand acceleration. Acceleration is the change in speed. When you let go of the up button, acceleration will be acting on the ship causing it to slow down and eventually stop. Acceleration in this case will be negative. When you are moving acceleration is 0; you are at constant speed; speed is not changing. When you let go of the up button acceleration is -1 in the direction where you are going. Now the ship's speed will keep decreasing until you stop (err.. until speed is 0 or lower). The speed in your game is the change in x and y of the ship's coordinates. I'll try to explain it more clearly if you still aren't sure on what to do.
Megatokyoguy




PostPosted: Wed Jun 06, 2007 11:34 am   Post subject: RE:Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

Wowza...I have no clue but the technical group mate of mine sort of does

O.o

Could you POSSIBLY, MAYBE give us either an example of the code for the acceleration OR where we would need to put it in our code?

We're getting down to the last couple of days now. It is due Friday. So far he wants to make it a multiplayer but I think that we really REALLY need asteroids.....

I know that you can't really help us with it but I would greatly appreciate some guidance.

Our teacher says that we can get some help so long as we cite where and from who.

You've been a great help so far.

And Invader Zim rox!

Razz
Sponsor
Sponsor
Sponsor
sponsor
CodeMonkey2000




PostPosted: Wed Jun 06, 2007 7:34 pm   Post subject: Re: Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

Take a look at this segment of code:
Turing:

if ship2_move = 1 then
    ship2_x := ship2_x + (10 * cosd (ship2_angle * 2 + 90) div 2)
    ship2_y := ship2_y + (10 * sind (ship2_angle * 2 + 90) div 2)
    ship2_angle := ship2_angle - 1
    if ship2_angle <= 0 then
        ship2_angle := 180
    end if


In
Turing:
10 * cosd (ship2_angle * 2 + 90) div 2
What would happen if that 10 was 0? You wouldn't move! So if you gradually decrease the 10 to 0 it will look like you are sliding (or that some external force is acting upon your ship.). Hope that helps.
BTW, this is because that 10 is the speed of the ship.
Megatokyoguy




PostPosted: Fri Jun 08, 2007 8:09 am   Post subject: RE:Asteroids game - Need guidance with collisions, projectiles - kinda working, and gravity

My group mate says that due to the size of the screen and the ships it didn't work.

We're pretty much done and we think it's a fairly good 2P game.

We acknowledged you in the code ;P

EDIT:

We got a 97%! YAY! Razz
We only lost out on effective use of class time Razz
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 10 Posts ]
Jump to:   


Style:  
Search: