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

Username:   Password: 
 RegisterRegister   
 HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!?
Index -> Programming, Turing -> Turing Help
Goto page Previous  1, 2
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
Tony




PostPosted: Fri Jan 14, 2011 6:53 pm   Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!?

What information do you need to describe the location and direction of a bullet? How does it change over time?
Latest from compsci.ca/blog: Tony's programming blog. DWITE - a programming contest.
Sponsor
Sponsor
Sponsor
sponsor
chaos




PostPosted: Fri Jan 14, 2011 11:12 pm   Post subject: Re: HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!?

to answer your question, try this:

%THIS IS PURPOSELY IN TEXT GRAPHICS, YOU HAVE FIGURE OUT THE REST YOURSELF IF YYOU WANT IT IN PIXEL GRAPHICS

View.Set("offscreenonly")
var bulletvelocity:int:=%set speed of bullet%
var playerx,playery:int:=20
var bulletx, bullety:int
var chars : array char of boolean
var bullet:boolean:=false
loop
Input.KeyDown

%
put movement code here
%

if chars(' ') then
bulletx:=playerx %When the fire key is pressed the bullet coordinates will be the player's current position
bullety:=playery
bullet:=true %this allows one bullet per player on screen; prevents spamming
end if
if bullet=true then
bulletx:=bulletx+bulletvelocity %This example will shoot the bullet right
if bulletx>maxx then
locate(bulletx,maxcol)
put" " %Clears the bullet if bullet is about to go off screen
else
locate(bullety,bulletx)
put"-" %Draws the bullet if it is not off screen
end if
delay(50)
View.Update
end loop
TokenHerbz




PostPosted: Sat Jan 15, 2011 12:49 am   Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!?

spawn at character --> move to destination... die when destination is reached....
nick4563




PostPosted: Sat Jan 15, 2011 9:57 am   Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!?

Thank you all Very Happy bullet velocity was my missing factor thank you!!!
Dragon20942




PostPosted: Tue Jan 18, 2011 7:59 pm   Post subject: RE:HELP!!! Making an if key pressed statement execute repeatedly after pressing the key only once!?

I'm currently making a shooting game for my culminating. Create another variable for the initial Y position of the bullet. Moving the bullet is just basic loop stuff.
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 2 of 2  [ 20 Posts ]
Goto page Previous  1, 2
Jump to:   


Style:  
Search: