Help with space invaders code
Author |
Message |
plokm
|
Posted: Sat Dec 17, 2011 5:29 pm Post subject: Help with space invaders code |
|
|
What is it you are trying to achieve?
<I'm trying to make a game like space invaders.>
What is the problem you are having?
Describe what you have tried to solve this problem
<I've been able to get the alien to scroll back and forth at the top and the ship can be controlled with the left and right arrow keys at the bottom of the screen but I don't have any idea on how to make it shoot.>
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
<Draw.FillBox (0, 0, maxx, maxy, black)
%%%%%%%%%%% SHIP %%%%%%%%%%%%%%
var logoPicID, spriteID : int
% The picture IDs of the logo and the background
var logoWidth, logoHeight : int
% The width and height of the logo picture
var x, y : int := 1 % The location of the logo
var dx, dy : int := 2 % The direction of movement of the logo
% Load the logo from file and get its height and width
logoPicID := Pic.FileNew ("ship.jpg")
logoWidth := Pic.Width (logoPicID )
logoHeight := Pic.Height (logoPicID )
% Create the sprite
spriteID := Sprite.New (logoPicID )
%Sprite.SetPriority (spriteID, 3)
Sprite.Show (spriteID )
%%%%%%%%%%ALIEN%%%%%%%%%%%%%%
var logoPicID1, spriteID1 : int
% The picture IDs of the logo and the background
var logoWidth1, logoHeight1 : int
% The width and height of the logo picture
var x1 : int := 0
var y1 : int := 375 % The location of the logo
var dx1, dy1 : int := 2 % The direction of movement of the logo
% Load the logo from file and get its height and width
logoPicID1 := Pic.FileNew ("alien.jpg")
logoWidth1 := Pic.Width (logoPicID1 )
logoHeight1 := Pic.Height (logoPicID1 )
% Create the sprite
spriteID1 := Sprite.New (logoPicID1 )
%Sprite.SetPriority (spriteID, 3)
Sprite.Show (spriteID1 )
%%%%%%%%%%%LASER%%%%%%%%%%%%%%%%%
var logoPicID2, spriteID2 : int
% The picture IDs of the logo and the background
var logoWidth2, logoHeight2 : int
% The width and height of the logo picture
var x2 : int := 0
var y2 : int := 375 % The location of the logo
var dx2, dy2 : int := 2 % The direction of movement of the logo
% Load the logo from file and get its height and width
logoPicID2 := Pic.FileNew ("laser.jpg")
logoWidth2 := Pic.Width (logoPicID2 )
logoHeight2 := Pic.Height (logoPicID2 )
% Create the sprite
spriteID2 := Sprite.New (logoPicID2 )
%Sprite.SetPriority (spriteID, 3)
Sprite.Show (spriteID2 )
loop
%%%%%%%%%SHIP%%%%%%%%%%
drawline (0, 0, 0, maxy, red)
drawline (maxx, maxy, maxx, 0, red)
drawline (0, 0, maxx, 0, red)
drawline (0, maxy, maxx, maxy, red)
x1 := x1 + dx1
%cls
if (y1 + logoHeight1 >= maxy) then
dy1 := dy1 * (- 1)
end if
if (x1 + logoWidth1 >= maxx) then
dx1 := dx1 * (- 1)
y1 := y1 - 20
end if
if (y1 <= 0) then
dy1 := dy1 * (- 1)
end if
if (x1 <= 0) then
dx1 := dx1 * (- 1)
y1 := y1 - 20
end if
Sprite.SetPosition (spriteID1, x1, y1, false)
var c : int := 1
var chars : array char of boolean
Input.KeyDown (chars )
if chars (KEY_RIGHT_ARROW) then % RIGHT
dx := 2
dy := 0
c := 6
end if
if chars (KEY_LEFT_ARROW) then % LEFT
dx := - 2
dy := 0
c := 7
end if
if (chars (chr (27)) or chars ('q')) then % ESCAPE or q to exit
exit
end if
delay (10)
%cls
%%%%%%%%%ALIEN%%%%%%%%%%
Sprite.SetPosition (spriteID, x, y, false)
drawline (0, 0, 0, maxy, red)
drawline (maxx, maxy, maxx, 0, red)
drawline (0, 0, maxx, 0, red)
drawline (0, maxy, maxx, maxy, red)
x := x + dx
delay (10)
if (y + logoHeight >= maxy) then
dy := dy * (- 1)
end if
if (x + logoWidth >= maxx) then
dx := dx * (- 1)
end if
if (y <= 0) then
dy := dy * (- 1)
end if
if (x <= 0) then
dx := dx * (- 1)
end if
%delay (10)
%cls
end loop
>
|
Please specify what version of Turing you are using
<Answer Here> |
|
|
|
|
![](images/spacer.gif) |
Sponsor Sponsor
![Sponsor Sponsor](templates/subSilver/images/ranks/stars_rank5.gif)
|
|
![](images/spacer.gif) |
plokm
|
Posted: Sat Dec 17, 2011 5:30 pm Post subject: RE:Help with space invaders code |
|
|
Im using 4-1-1a |
|
|
|
|
![](images/spacer.gif) |
Raknarg
![](http://compsci.ca/v3/uploads/user_avatars/3745510004d8be6689b92f.jpg)
|
Posted: Sat Dec 17, 2011 5:49 pm Post subject: RE:Help with space invaders code |
|
|
if trigger is pulled
shoot a bullet (set the initial x and y values)
end if
if bullet is in the same spot as enemy then
kill enemy
kill bullet
end if
if bullet is out of bounds then
kill bullet
end if
move bullets
move enemies
move ship
This is the basic logic for a shooting game. |
|
|
|
|
![](images/spacer.gif) |
|
|