
-----------------------------------
Shardul
Thu Feb 21, 2008 10:09 pm

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. :P ). Anyways please give suggestions on how to fix the problem and just don't post code please because I want to learn what I am doing. Also I realize the code is probably very inefficient as I have been learning Turing for bout a week. So whatever you change please tell me. Thanks.  :D 

The CODE. The actual file is given below.
%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.  :)

-----------------------------------
TokenHerbz
Fri Feb 22, 2008 6:57 am

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.

-----------------------------------
Shardul
Fri Feb 22, 2008 3:48 pm

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. :(

-----------------------------------
daklezardo
Sat Feb 23, 2008 4:25 pm

Re: Help my bullet slows down
-----------------------------------
try setting the bullet to speed up when the character moves

-----------------------------------
TokenHerbz
Sun Feb 24, 2008 12:57 pm

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..

-----------------------------------
Tony
Sun Feb 24, 2008 1:19 pm

Re: Help my bullet slows down
-----------------------------------
If I put a delay outside the loop it will still slow it down. :(
don't use delays when you don't have to.

-----------------------------------
Shardul
Wed Feb 27, 2008 7:57 pm

Re: 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..
Ok I will try to find a simpler way but I don't see how. Any help where I can simplify it?

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

-----------------------------------
Tony
Wed Feb 27, 2008 8:40 pm

Re: RE:Help my bullet slows down
-----------------------------------
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.

-----------------------------------
Shardul
Tue Mar 18, 2008 3:22 pm

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.  :D

-----------------------------------
Sean
Tue Mar 18, 2008 3:53 pm

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.

-----------------------------------
Insectoid
Thu Mar 27, 2008 2:42 pm

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: 

picMan := Pic.FileNew ("Man.bmp") 
spriteMan := Sprite.New (picMan) 

with 'illegall picture ID number '0''
