Computer Science Canada Help my bullet slows down |
Author: | Shardul [ Thu Feb 21, 2008 10:09 pm ] |
Post subject: | Help my bullet slows down |
Ok so I am starting Grade 10 Computer Science and I finished the excersises the teacher gave us much before my class. So I checked out how to use sprites and move them around with some level of sucess. The problem is that the bullet moves fine when the character that shot it is not moving but when he starts moving the bullet slows down a lot, maybe even to half of its speed. So I am wondering why it is doing this. The example below is my game in BETA BETA BETA STAGE. (THAT IS WHY THE SPRITES LOOK SO CRAPPY. ![]() ![]() The CODE. The actual file is given below. Quote: %Made by Shardul Upadhyay
%Declare sprite variable and related variables associated to moving sprite var picMan, spriteMan, picBack, spriteBack, picBullet, spriteBullet : int var centered : boolean := false var x, y : int := 100 var chars : array char of boolean %Declare "mousewhere" variables var mousex, mousey, button : int %Shooting variables var shoot : int := 0 var bulletx, bullety : int := 0 %Create sprites picMan := Pic.FileNew ("Man.bmp") spriteMan := Sprite.New (picMan) picBack := Pic.FileNew ("Background.bmp") spriteBack := Sprite.New (picBack) picBullet := Pic.FileNew ("Bullet.bmp") spriteBullet := Sprite.New (picBullet) %Create sprites Sprite.Animate (spriteMan, picMan, x, y, centered) Sprite.Show (spriteMan) Sprite.Animate (spriteBack, picBack, 0, 0, centered) Sprite.Show (spriteBack) Sprite.SetHeight (spriteBack, -10) loop %Move up and down code Input.KeyDown (chars) if chars (KEY_UP_ARROW) then Sprite.Animate (spriteMan, picMan, x, y, centered) delay (10) y += 1 elsif chars (KEY_DOWN_ARROW) then Sprite.Animate (spriteMan, picMan, x, y, centered) delay (10) y -= 1 elsif chars (KEY_RIGHT_ARROW) then Sprite.Animate (spriteMan, picMan, x, y, centered) delay (10) x += 1 elsif chars (KEY_LEFT_ARROW) then Sprite.Animate (spriteMan, picMan, x, y, centered) delay (10) x -= 1 end if %Shooting code mousewhere (mousex, mousey, button) if button = 1 then Sprite.Animate (spriteBullet, picBullet, x + 64, mousey, centered) Sprite.Show (spriteBullet) shoot := 1 bullety := y + 105 end if if shoot = 1 then loop bulletx += 1 Sprite.Animate (spriteBullet, picBullet, x + 64 + bulletx, bullety, centered) Sprite.Show (spriteBullet) delay (2) exit when x > 64 end loop end if end loop Thanks for any help provided. ![]() |
Author: | TokenHerbz [ Fri Feb 22, 2008 6:57 am ] |
Post subject: | RE:Help my bullet slows down |
You need to do a few things.. First i would take out all those delays in your character move, and put those into your main loop. Which brings me to the use of functions.. But for now what i see in your code, is after your bullet is created and starts moving, its got no speed delays, so when you move your character with a delay of 20, The bullet then has to wait for that delay to pass, as that delay effects your whole code. |
Author: | Shardul [ Fri Feb 22, 2008 3:48 pm ] |
Post subject: | Re: Help my bullet slows down |
Ok now I see the problem but how do I fix the problem? If I put a delay outside the loop it will still slow it down. ![]() |
Author: | daklezardo [ Sat Feb 23, 2008 4:25 pm ] |
Post subject: | Re: Help my bullet slows down |
try setting the bullet to speed up when the character moves |
Author: | TokenHerbz [ Sun Feb 24, 2008 12:57 pm ] |
Post subject: | RE:Help my bullet slows down |
try to think of the simplest way, it's best not to over complicate things when you don't have too.. |
Author: | Tony [ Sun Feb 24, 2008 1:19 pm ] |
Post subject: | Re: Help my bullet slows down |
Shardul @ Fri Feb 22, 2008 3:48 pm wrote: If I put a delay outside the loop it will still slow it down.
![]() don't use delays when you don't have to. |
Author: | Shardul [ Wed Feb 27, 2008 7:57 pm ] |
Post subject: | Re: RE:Help my bullet slows down |
TokenHerbz @ Sun Feb 24, 2008 12:57 pm wrote: try to think of the simplest way, it's best not to over complicate things when you don't have too..
Ok I will try to find a simpler way but I don't see how. Any help where I can simplify it? Tony wrote: Shardul @ Fri Feb 22, 2008 3:48 pm wrote: If I put a delay outside the loop it will still slow it down.
![]() don't use delays when you don't have to. The problem is that I have to use delay's to slow down the bullet and the character or the character and bullet move so fast u can't see them and they are only moving by the lowest possible integer (1) since you can't use a rela number for the x value. Any ideas on how to get it to move at the speed I want without delays or how to get around the delays. ![]() Thank you very much for the help. Shardul |
Author: | Tony [ Wed Feb 27, 2008 8:40 pm ] |
Post subject: | Re: RE:Help my bullet slows down |
Shardul @ Wed Feb 27, 2008 7:57 pm wrote: since you can't use a rela number for the x value.
yes you can, you just need to round the real value before drawing the pixel. |
Author: | Shardul [ Tue Mar 18, 2008 3:22 pm ] |
Post subject: | Re: Help my bullet slows down |
Can someone help me please? I had a lot of work so I was unable to get back to my game but I have just started trying to find a solution this week and I can't seem to find a solution. Can someone make some changes to the code posted above or post an example. Thanks. ![]() |
Author: | Sean [ Tue Mar 18, 2008 3:53 pm ] |
Post subject: | Re: Help my bullet slows down |
As you know, we can't do the work for you. But, we can assist. Read over what is above, they tell you must of what you require. |
Author: | Insectoid [ Thu Mar 27, 2008 2:42 pm ] | ||
Post subject: | RE:Help my bullet slows down | ||
Geez! you've been doing it for a week and you already can do this!?!?!?!?! I must have the WORST computer science teacher in the world! I'm more than a month into my class and we haven't gotten out of sequential stuff! My teacher has only taught text so far. I can't run it, it crashes here:
with 'illegall picture ID number '0'' |
: |