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

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




PostPosted: Wed Jun 08, 2005 8:23 pm   Post subject: Firing

Ok, I have created a graphic to use as a bullet but the problem is that the bullet graphic doesn't move vertically but stays stationary. Mind you this accident allows me to use it as a muzzle flash for when the player presses the shoot button

Part of my Input Procedure
code:
    if chars (' ') then
        Weapon_fired :=true
   end if
end P1_CheckKeys


the actual Procedure responsible for the bullet
code:
procedure Shoot
    if Weapon_fired =true then
    Bullet_X := charX+18
    Bullet_Y := charY+Bullet_Speed
    Pic.Draw(Tracer,Bullet_X,Bullet_Y,picMerge)
    Weapon_fired :=false
    end if
end Shoot   
Sponsor
Sponsor
Sponsor
sponsor
Delos




PostPosted: Wed Jun 08, 2005 8:34 pm   Post subject: (No subject)

Here's what you'll want to do. Your 'bullet' is an object, with a cartesian cordinate, a velocity, and perhaps other attributes as well.
So:
Turing:

type bullet:
  record
    pX, pY : int
    vX, vY : int
    fired : boolean
    col : int
  end record


Now, when your bullet is created, you assign each of the fields of the record (eg. my_bullet.pX := 5) however you need. Probably 'fired' will be initially false.
Now, your check for input sets the boolean to true (as a note, you don't need to include the comparison check with booleans: 'if fired then' is the same as 'if fired=true then') and you draw your object. By this time of course, you've also initialized the velocity components - allowing you both vertical and angled movement.
Just make sure that at regular intervals, the 'pX' of the object has the 'vX' added to it (and the same for the y-components).

Check out the tutorials on records and types, as well as on arrays.
vagyb




PostPosted: Wed Jun 08, 2005 9:07 pm   Post subject: Re: Firing

you have to make the change of the bullet X coordinate after the weopon_fired : = true

Nitrix wrote:

code:
    if chars (' ') then
        Weapon_fired :=true
(here put ur bullet X and Y coordinates for example)
   if chars (' ') then
            isShooting := true
           bulletx += 93
       
        end if
end P1_CheckKeys



the actual Procedure responsible for the bullet
code:
procedure Shoot
    if Weapon_fired =true then
    Bullet_X := charX+18
    Bullet_Y := charY+Bullet_Speed
    Pic.Draw(Tracer,Bullet_X,Bullet_Y,picMerge)
    Weapon_fired :=false
    end if
end Shoot   
vagyb




PostPosted: Wed Jun 08, 2005 9:07 pm   Post subject: (No subject)

also if ur doing a shooter game check my thread on this forum (it should be on this page) , i'm pretty sure it'll help u a bit.
Nitrix




PostPosted: Thu Jun 09, 2005 2:55 pm   Post subject: (No subject)

Ok I got my ship to shoot but the problem is that it will only works randomly and when it does it will only fire once. Forgive but I am a total noob when it comes to arrays(especiallyt when they involve pictures).
vagyb




PostPosted: Thu Jun 09, 2005 8:25 pm   Post subject: (No subject)

Nitrix wrote:
Ok I got my ship to shoot but the problem is that it will only works randomly and when it does it will only fire once. Forgive but I am a total noob when it comes to arrays(especiallyt when they involve pictures).


post the code?
Nitrix




PostPosted: Thu Jun 09, 2005 8:40 pm   Post subject: (No subject)

code:
    if Weapon_fired =true then
    Bullet_X := charX+18
    Bullet_Y := charY+48
    Pic.Draw(Tracer,Bullet_X,Bullet_Y+Bullet_Speed,picMerge)
    Weapon_fired :=false
    Bullet_X := charX
    Bullet_Y := charY
    end if
vagyb




PostPosted: Thu Jun 09, 2005 8:46 pm   Post subject: (No subject)

Nitrix wrote:
code:
    if Weapon_fired =true then
    Bullet_X := charX+18
    Bullet_Y := charY+48
    Pic.Draw(Tracer,Bullet_X,Bullet_Y+Bullet_Speed,picMerge)
    Weapon_fired :=false
    Bullet_X := charX
    Bullet_Y := charY
    end if


okay why are u changing ur bullet Y value? u only change the bullet X value when u shoot, do not draw the bullet in that if statement, and make new statement if weopon fired false then bullet x : = charx etc...
[/code]
Sponsor
Sponsor
Sponsor
sponsor
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  [ 8 Posts ]
Jump to:   


Style:  
Search: