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

Username:   Password: 
 RegisterRegister   
 alien invaders
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
shoobyman




PostPosted: Tue May 30, 2006 5:18 pm   Post subject: alien invaders

controls are mouse to move and click to shoot

this is for my alien invader game. it has 2 problems.
1. when you shoot, the laser moves with you.
2. when you let go of the mouse button, the bullet dissapears.

can anyone help me fix these problems?



ALIEN INVADERS.zip
 Description:

Download
 Filename:  ALIEN INVADERS.zip
 Filesize:  6.46 KB
 Downloaded:  87 Time(s)

Sponsor
Sponsor
Sponsor
sponsor
TheOneTrueGod




PostPosted: Tue May 30, 2006 5:54 pm   Post subject: (No subject)

Er... the answer is kinda staring you in the face in your code... Razz

code:

    if button = 1 then
        bulx := x + 2
        buly += 10
        drawline (bulx, buly, bulx, buly + 25, 12)
    end if
    if button not= 1 then
        buly := 90
    end if


you are allways setting the bullet's x to the mouse's x when the button is down, and if the button isn't down, then you're allways setting the bullet y to 90...

Instead, have a flag that keeps track of if the bullet is fired or not, and update the bullets position if it is fired. When the bullet goes off screen (or later hits someone) make it so the flag updates that. Make sure you can only shoot when this flag is false. (by flag, I mean boolean, though really, you can use anything for a flag if you feel like it.)

Of course, there are many better ways to do this, such as arrays or even better, flexible arrays, so you can fire more than one bullet at once (Though in the case of the 'alien invaders' game [if you're thinking of the same one I am], there is only one bullet anyways). That should pretty much cover it.
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: