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

Username:   Password: 
 RegisterRegister   
 Turing Challenge for SWAT staff!
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Asok




PostPosted: Thu Mar 06, 2003 4:44 pm   Post subject: Turing Challenge for SWAT staff!

Hey guys, I'm making a space invader type game (Space Invaders II, I'll upload it when it's done) anyways here's the challenge: I need to recieve multiple inputs, one for the direction and one to shoot. It is possible to get it from the same variable however the shot will not continue to move when you change direction because now the getch variable is now holds something other than shoot. So here's the objective: Get the shot to continue moving on the same x axis as it was origionally shot from and to progrssively move along the y axis. At the same time (or slightly after the shot is in motion) be able to move an object (the ship) without the ball disapearing or following the ship's x axis.

Because this is more conceptual you do not need to actually make things look like anything, simple Draw.Oval pictures will be fine.

What it does require is atleast one getch for the direction of the ship the rest is up to you.

code:
var direction : string (1) := ""
var shipx : int := 100
var shipy : int := 100
process gtch
getch (direction)
end gtch
loop
cls
fork gtch
if direction = "w" then
shipy := shipy + 1
elsif direction = "s" then
shipy := shipy - 1
elsif direction = "a" then
shipx := shipx - 1
elsif direction = "d" then
shipx := shipx + 1
end if

Draw.FillOval (shipx, shipy,10,10,red)
delay (50)
end loop


This is the code to get the object to move through WSAD keyboard input the trick is getting the shot. simply adding
code:
elsif direction = " " then
draw bullet

will not work because the bullet will disappear when there is another keyboard input because direction no longer equals space so it will no longer be called.

Good Luck.
Sponsor
Sponsor
Sponsor
sponsor
Tony




PostPosted: Thu Mar 06, 2003 6:18 pm   Post subject: (No subject)

thats the thing... on if key = " " it should FIRE the bullet, not just draw it...

so you set bullet flag to true and bullet location to ship location.

then have a separate process move the bullet along Y axis as long as the flag is true. Set flag to false when bullet leaves the screen or hit other object.

The drawback is that you can have only a single bullet on a screen. You can fix that by ether

a) Have a lazer instead so it reaches the end of screen much faster

or

b) use an array for the bullets and have a counter going on that as soon as you have more then w/e number of bullets, you go back and use 1st variable.
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
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  [ 2 Posts ]
Jump to:   


Style:  
Search: