Very basic, barely started space shooter
Author |
Message |
The9thPawn
|
Posted: Fri Nov 07, 2008 8:42 pm Post subject: Very basic, barely started space shooter |
|
|
Hey I'm doing programming for the first time at my highschool, and one of our projects is to make a game. Ive decided to do a space shooter. The spaceship (the only thing on the screen......so far) is the black square, and it can be moved using the arrow keys. However there is nothing stopping the user from steering the spaceship right off the screen, and I wanted to know if there was any way to stop this from happening, any help would be apreeciated. The program is below.
% November 7, 2008
View.Set ("graphics:<1000>; <800>")
var chars : array char of boolean
var a, b, c, d, e, f, g, h: int
a := 0
b := 30
c := 0
d := 30
e := 0
f := 30
g := 0
h := 30
loop
Input.KeyDown (chars)
locate (1, 1)
if chars (KEY_UP_ARROW) then
a := a + 3
b := b + 3
e := a - 30
f := b - 30
delay (10)
drawfillbox (c, a, d, b, black)
drawfillbox (c, e, d, f, white)
else
put " " ..
end if
if chars (KEY_RIGHT_ARROW) then
c := c + 3
d := d + 3
g := c - 30
h := d - 30
delay (10)
drawfillbox (c, a, d, b, black)
drawfillbox (g, a, h, b, white)
else
put " " ..
end if
if chars (KEY_LEFT_ARROW) then
c := c - 3
d := d - 3
g := c + 30
h := d + 30
delay (10)
drawfillbox (c, a, d, b, black)
drawfillbox (g, a, h, b, white)
else
put " " ..
end if
if chars (KEY_DOWN_ARROW) then
a := a - 3
b := b - 3
e := a + 30
f := b + 30
delay (10)
drawfillbox (c, a, d, b, black)
drawfillbox (c, e, d, f, white)
else
put " " ..
end if
end loop |
|
|
|
|
 |
Sponsor Sponsor

|
|
 |
pavol
|
Posted: Fri Nov 07, 2008 8:51 pm Post subject: Re: Very basic, barely started space shooter |
|
|
to make sure the ship doesn't go off the screen you can take your variable for the x position of the spaceship and add a bounds check for when you add or subtract the value. So, for example if the left key is pressed and the ship x value is not smaller than 0, then subtract from it.
Also a tip for making your program more readable, give descriptive variable names like xPosition and yPosition, not a b c d e f...[/code] |
|
|
|
|
 |
|
|