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

Username:   Password: 
 RegisterRegister   
 How to move and shoot at the same time
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
NeutronX




PostPosted: Thu Nov 08, 2007 4:01 pm   Post subject: How to move and shoot at the same time

I am making a game that required a car to shoot rockets but I want it to drive at the same time and not just stop. How can I move and shoot at the same time?

Here's the code:

code:

var bullety : int
var bulletx : int
bulletx := 00
bullety := 200
var bullet : int
var chars : array char of boolean
var x, y, x1, y1 : int
var Shooting : boolean := false

x := 00
y := 200

View.Set ("offscreenonly")
    var pic1 : int := Pic.FileNew ("bullet.bmp")
    var sprite1 : int := Sprite.New (pic1)
    var pic2 : int := Pic.FileNew ("coolcar2.bmp")
    var sprite2 : int := Sprite.New (pic2)

loop
    Sprite.Show(sprite2)
    Sprite.SetPosition (sprite2, x, y,true)
   
    Input.KeyDown (chars)

    if chars (KEY_RIGHT_ARROW) then
        x := x + 5
        bulletx := bulletx + 5
        if x > maxx then
            x := x- 5
            bulletx := bulletx - 5
        end if
    end if
    if chars (KEY_LEFT_ARROW) or chars ('s') then
        x := x - 5
        bulletx := bulletx - 5
        if x < 0 then
            x := x + 5
            bulletx := bulletx + 5
        end if
       
    end if
 
      if chars (' ') then
        for i: x .. 690 by 10           
        Sprite.Show (sprite1)
        Sprite.SetPosition (sprite1, i, y, true)
       
        delay (1)
        View.Update
        Sprite.Show(sprite2)
        Sprite.SetPosition (sprite2, x, y,true)   
            end for
        end if

        if bulletx > 640 then
            Shooting := false
            bulletx := -20
        end if 
   
    View.Update
end loop


Edited by Clayton: I'm about to give up on this... but... USE CODE TAGS!!





PLZ HELP!
Sponsor
Sponsor
Sponsor
sponsor
HeavenAgain




PostPosted: Thu Nov 08, 2007 4:07 pm   Post subject: RE:How to move and shoot at the same time

you'll better edit this code before a mod comes here and go crazy again (they are on a roll these days Wink), use code tag!
code:
[code]blah blah blah[/code]


and i think this have something to do with Input.KeyDown

but i could be wrong Very Happy

Edit: oh and if left arrow key is pressed and s is pressed, that if statement should be and instead of or
LaZ3R




PostPosted: Thu Nov 08, 2007 5:29 pm   Post subject: RE:How to move and shoot at the same time

Your code needs some revamping...

You currently have it so that the player has to HOLD arrow keys to control the location of a bullet.

If I hold RIGHT ARROW for 2 seconds and let go, the bullet will stop moving.

You also for some reason have it setup so that you are always on the location of the bullet because if I hold right, the x cord of the bullet will increase by 5 but so will the location of the car in this case.

What you should do is go through your code line by line and make sure what you want it to do makes sense.
Zampano




PostPosted: Thu Nov 08, 2007 6:17 pm   Post subject: Re: How to move and shoot at the same time

Use processes!
You probably have heard of procedures; processes are the same except they run at the same time as other processes. This would allow you to have a process for shooting and another for driving run concurrently. Look in on processes in F10.
Saad




PostPosted: Thu Nov 08, 2007 6:58 pm   Post subject: RE:How to move and shoot at the same time

I suggest you not use processes and look into Input.KeyDown, processes are not usefull is this situation
Zampano




PostPosted: Thu Nov 08, 2007 8:04 pm   Post subject: Re: How to move and shoot at the same time

You know better than I the best method. If there is an efficient way to do it with just Input.KeyDown (more complex visuals are difficult in a loop that relies on the activation of an if) then you should do that instead of using processes.
Processes may be convenient sometimes, but they are troublesome even more often . . .
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  [ 6 Posts ]
Jump to:   


Style:  
Search: