I Need Help On Angled Projectiles!
Author |
Message |
DemonZ
|
Posted: Fri Oct 27, 2006 5:35 pm Post subject: I Need Help On Angled Projectiles! |
|
|
I Am currently making my grade 11 final project, which is supposed to be battle tanks, a birds eye view of Tanks that you move around with and shoot the other tank, the problem I am having is with the controls, I got the tank to rotate and move according to the arrows, but I am having trouble with the projectile, meaning: The projectile that is supposed to fire from the tank doesnt animate or even move what so ever. Any way here is the whole entire game with the pics and coding, just run it and try to shoot with the tank youll kinow what I mean. I really appreciate any help, thanks. The arrows move your tank and NUM 0 is to shoot.
Description: |
|
Download |
Filename: |
Battle Tank controls.zip |
Filesize: |
36.99 KB |
Downloaded: |
79 Time(s) |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
jamonathin
|
Posted: Sat Oct 28, 2006 12:13 am Post subject: (No subject) |
|
|
I'll give you a hint, since its ur FP. Here is what you need to do to smoothly rotate your tank. Now what you need to do is correspong the center of your new tank to the start of your projectile and (theoricically) it should appear to fire from the cannon of your tank
code: |
procedure Tank
Pic.Draw (pic (Tank_angle), round (x) - Pic.Width (pic (Tank_angle)) div 2, round (y) - Pic.Height (pic (Tank_angle)) div 2, picMerge)
end Tank |
Now what you need to do is fix this
code: |
for dist : 1 .. 300
Bx := Bx - dx
By := By + dy
Pic.Draw (pic2 (Tank_angle), round (x) + round (Bx), round (y) + round (By), picMerge)
end for |
This is why ur bulllet looks like a line.
WHat you need to do is remove that for loop and use a condition such as
Pseudo: |
If Math.Disatance (bulletx,bulllety,tankx,tanky) < 100 then
move bullet
( Bx := Bx - dx
By := By + dy)
checkIfBulletHitSomething
end if |
that way your bullet moves with normal time, and not in a for loop where nothing else is refreshed.
If you need any help understanding what I said just ask .
|
|
|
|
|
|
DemonZ
|
Posted: Tue Oct 31, 2006 8:32 am Post subject: (No subject) |
|
|
Thanks it really helped me out allot, but lets say I wanted to make this game 2 players, using controls for P1 tank and controls for P2 tank, would I use a process or a procedure? I tried this already and when I used a process for player 1 and player 2 it turned out that the game began to flicker allot instead of playing smoothly, but im just wondering if procedure would be recomended, any way thanks alot it really helped me out alot.
|
|
|
|
|
|
jamonathin
|
Posted: Tue Oct 31, 2006 12:48 pm Post subject: (No subject) |
|
|
Well, simply processes suck. They are only really good for playing background music. They dont work as well as you would think they do.
The biggest thing you'll have to do when making a 2p game, or any game that uses 2 people or 1 and a computer is ... use only 1 delay. You dont want P1 to be shooting, and since he's shooting, player 2 is on pause. Here is some simple Pseudo/turing code on how to make 2 people shoot
pseudo: |
proc player1shoot
if key (SPACEBAR) then
shoot = true
missileX = player1X
end if
if shoot = true then
missileX += 5
end if
if shoot = true and missileX > range or missileHitSomething = true then
missileX := 0
shoot := false
end if
end player1shoot |
Basically what happens is we have the missile moving by 5 units while everything else in the game is going on. We aren't pausing the game while the missile shoots, we are just letting it move in the background. Im in a lil bit of a rush so if u need any more clarification lemme know .
|
|
|
|
|
|
DemonZ
|
Posted: Tue Oct 31, 2006 4:27 pm Post subject: (No subject) |
|
|
Thanks alot i understand it now, if i have any problems ill jump back into the forums for help, Thanks though.
|
|
|
|
|
|
DemonZ
|
Posted: Tue Oct 31, 2006 5:07 pm Post subject: (No subject) |
|
|
Ok it turns out I ran into a problem, when I use ur pseudo form of Math.Distance, do I include some sort of loop to make the bullet move, because when I use the if statement, it will not animate and just stay at its original place which is the starting point of where the bullet is created.
|
|
|
|
|
|
DemonZ
|
Posted: Tue Oct 31, 2006 5:47 pm Post subject: (No subject) |
|
|
Ok never mind i fixed it, dont worry about it, the thing is I dont think u understand how I want the bullet to move, I want it to be like when the player presses the button to shoot the bullet, his tank, and his tank only is frozen and cannot move while the bullet travels to a certain distance and is erased from the screen, this way the tank does not surpass the bullet moving and it simulates how a real tank fires, what u showed me with math distance is that when I hold down the fire key the bullet travels, but I want it to be so that when u press the fire key once, the bullet will travel to its specified point and then erase itself, and at that time, the bullets x and y values are reset back to the tanks x and y coordiantes and when the user presses the fire key again, the same thing will happen. Anyway thanks again for some of the hints because it really did help, but u misunderstood how I wanted the projectile to respond to the controls pressed at that time. If u can help me solve this problem it would be a huge help.
|
|
|
|
|
|
jamonathin
|
Posted: Tue Oct 31, 2006 8:40 pm Post subject: (No subject) |
|
|
Ok, well if you dont want your tank to move, it shouldn't be that hard to put in. Some where in your program you are going to have a variable that says, "Hey, Player 1 is shooting!". If and when that happens, just restrict the player from being able to move the tank like such:
pseudo: |
if player1IsShooting = FALSE then
if key LEFT_ARROW then // P1 Moving statements
x - 10
elsif ......
.........
end if
end if |
You can either have that (where it wraps everything up) or put "player1IsShooting = FALSE" at the end of each moving 'if' statement.
If you want your bullet to blow up when pressing space (after it's been fired), just use the same concept
pseudo: |
if player1IsShooting = FALSE and key (SPACEBAR) then
- start shooting missile
player1IsShooting = TRUE
(p1 tank cant move now)
elsif player1IsShooting = TRUE and key (SPACEBAR) then
- blow up missile
- reset variables
- player1IsShooting = FALSE
(p1 tank can move now)
end if |
Hope that clears some stuff up.
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
DemonZ
|
Posted: Tue Oct 31, 2006 9:29 pm Post subject: (No subject) |
|
|
Thanks alot it really helped out my controls between the two players, if I had a hundred bits I would donate them to you.
|
|
|
|
|
|
|
|