Computer Science Canada

Running something in backround?

Author:  bc123 [ Sat Jan 21, 2012 11:40 pm ]
Post subject:  Running something in backround?

What is it you are trying to achieve?
I want a loop to be running in backround. Example : A loop is animating a missle coming to a character, i want the user to be able to move the character, but still have that missle moving smoothly

What is the problem you are having?
Ny problem at the moment is im unsure how to do it, i was told by a friend to use procedures, but have never worked with it, and i so far have a moving character (a moving square) but still unsure how to add in the missle

Turing:


var x1 : int := 300 % used for coords of character|
var y1 : int := 10  %                             |
var x2 : int := 330 %                             |
var y2 : int := 40  %                             |
%_________________________________________________|
var x3 : int := 700 % used for coords of missle  |
var y3 : int := 10  %                            |
var x4 : int := 670 %                            |
var y4 : int := 40  %                            |
%________________________________________________|
var col : int := 52 % color of character
var pressed : array char of boolean

Draw.FillBox (x1, y1, x2, y2, col)

loop

    Input.KeyDown (pressed)

    if pressed (KEY_UP_ARROW) then

        y1 := y1 + 10
        y2 := y2 + 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 + 10
        y2 := y2 + 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 + 10
        y2 := y2 + 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 + 10
        y2 := y2 + 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 - 10
        y2 := y2 - 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 - 10
        y2 := y2 - 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 - 10
        y2 := y2 - 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 - 10
        y2 := y2 - 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 - 10
        y2 := y2 - 10
        delay (50)
        View.Update
        cls

        Draw.FillBox (x1, y1, x2, y2, col)

    end if

    if pressed (KEY_LEFT_ARROW) then

        x1 := x1 - 10
        x2 := x2 - 10
        delay (50)
        View.Update
        cls
        Draw.FillBox (x1, y1, x2, y2, col)

    end if

    if pressed (KEY_RIGHT_ARROW) then

        x1 := x1 + 10
        x2 := x2 + 10
        delay (50)
        View.Update
        cls
        Draw.FillBox (x1, y1, x2, y2, col)

    end if
end loop




Please specify what version of Turing you are using
<Answer Here>

Author:  bc123 [ Sat Jan 21, 2012 11:45 pm ]
Post subject:  RE:Running something in backround?

also, forgot to mention i forgot how to make a limit on how far the x1 and x2 can move to :s any ideas?

Author:  Alex C. [ Sat Jan 21, 2012 11:56 pm ]
Post subject:  Re: Running something in backround?

yeah, what version of turing Rolling Eyes

Author:  Alex C. [ Sat Jan 21, 2012 11:57 pm ]
Post subject:  RE:Running something in backround?

oh and second, do you have any code for your missile? (stronger straight forward attack or homing missile)

Author:  bc123 [ Sat Jan 21, 2012 11:59 pm ]
Post subject:  RE:Running something in backround?

4.1.1

and no, i only have variables set for the missle
and another example of what i want, im working on this other game, and ill need this to have a backround constantly scrolling, then there will be a character that is running in one spot.
thnx
EDIT :
oh and i am going for a side attack, either from left or right

Author:  Alex C. [ Sun Jan 22, 2012 12:04 am ]
Post subject:  RE:Running something in backround?

make your missile coordinate try to be as close to the the characters coordinates...

example

charx>missilex
missilex-5

etc

Author:  Alex C. [ Sun Jan 22, 2012 12:05 am ]
Post subject:  RE:Running something in backround?

for limiting x and y...

if char x > maxboundaryx then
char x -= amount character moved right....

etc Very Happy

Author:  bc123 [ Sun Jan 22, 2012 12:06 am ]
Post subject:  RE:Running something in backround?

im confused :s why do charx > misslex? also i made this little example, of how i would animate a missle

Turing:

var x3 : int := 700
var y3 : int := 10 
var x4 : int := 670
var y4 : int := 40 
loop
Draw.FillBox (x3, y3, x4, y4, black)

x3 := x3 - 10
x4 := x4 - 10
delay (50)
View.Update
cls
Draw.FillBox (x3, y3, x4, y4, black)
end loop

Author:  Alex C. [ Sun Jan 22, 2012 12:09 am ]
Post subject:  RE:Running something in backround?

the greater the x value the farther right you are...
so if you want the missile to follow you and you are farther right, you add to the missiles x value to make it go FARTHER RIGHT Very Happy

simple math... ROFL

Author:  bc123 [ Sun Jan 22, 2012 12:10 am ]
Post subject:  RE:Running something in backround?

oh, i just figured out limits my own way :s i bassicaly did
if x1 > 11 then
x1 := x1 + 10
end if
if x2 > 31 then
x2 := x2 + 10
end if

Very Happy and the box is 30x30 (i think :s) but it does work :s jus a little more pointless lines of code

Author:  Alex C. [ Sun Jan 22, 2012 12:12 am ]
Post subject:  RE:Running something in backround?

by the way your jumping makes you go farther into the ground... Confused

Author:  bc123 [ Sun Jan 22, 2012 12:12 am ]
Post subject:  RE:Running something in backround?

well my idea is no matter what, the missle would scroll across the screen, and your character would jump over it, and the missle would continue on, but if i had a loop with an animation of a missle scrolling with its own delays, if i press the arrow keys and delay the characters movement, then wouldnt it affect the speed of the missle??

Author:  bc123 [ Sun Jan 22, 2012 12:15 am ]
Post subject:  RE:Running something in backround?

yes, i realized that when i ran it, just remove one of these chunks

Turing:
        Draw.FillBox (x1, y1, x2, y2, col)
        y1 := y1 - 10
        y2 := y2 - 10
        delay (50)
        View.Update
        cls
[/syntax]

Author:  Alex C. [ Sun Jan 22, 2012 12:16 am ]
Post subject:  RE:Running something in backround?

no...

loop
box moves...
delay
missile moves...
delay
endloop

how many times is the character delayed in comparision to the missile? Smile

Author:  bc123 [ Sun Jan 22, 2012 12:18 am ]
Post subject:  RE:Running something in backround?

well if u jump, i have like 6 delays, wont that affect the missle? like it will take longer to get through the loop to add distance to the missle and output it

Author:  Alex C. [ Sun Jan 22, 2012 12:19 am ]
Post subject:  RE:Running something in backround?

yeah but how many times does the character move in that loop.... once... smae with the missile! Very Happy

Author:  bc123 [ Sun Jan 22, 2012 12:24 am ]
Post subject:  RE:Running something in backround?

ahh, well where should i try putting the missle animation? above all the if key ???

Author:  bc123 [ Sun Jan 22, 2012 12:35 am ]
Post subject:  RE:Running something in backround?

Okay, so i tried this,

x3 := x3 - 10
x4 := x4 - 10

delay (50)
View.Update
cls
Draw.FillBox (x1, y1, x2, y2, col)
Draw.FillBox (x3, y3, x4, y4, black)

this is above all the if key
now i see the black square on startup, but then it disappears and only the original character sqaure is left showing
i also removed the delays from the ifs so there is only 1 single delay in the whole loop

Author:  bc123 [ Sun Jan 22, 2012 12:51 am ]
Post subject:  RE:Running something in backround?

ahh, good news, ive got the delays working fine, missle is fine, collison is find to my liking at the moment, now i need to figure how how to move left and right while in air, any ideas?

Author:  Alex C. [ Sun Jan 22, 2012 1:13 am ]
Post subject:  RE:Running something in backround?

multiple if statements one after the other (no elsifs...)

Author:  bc123 [ Sun Jan 22, 2012 1:27 am ]
Post subject:  RE:Running something in backround?

hmm, actually, i changed my mind and im now working on shooting, now my idea is correct, but im having trouble writing it in turing

PSEUDO : press space, shoot from character coordinates, if the bullet hits missle, missle resets to original coords.

Now, i know my problem, and still unsure how to fix it.

Problem: Everything moves in increments of 10, if im 15 pixels away from missle and i shoot, ill be adding on odd numbers, not being able to colide with the missle.

Is there a way to code if bullet is withing the range of the missle then reset?

Author:  bc123 [ Sun Jan 22, 2012 1:45 am ]
Post subject:  RE:Running something in backround?

also, i quickly tried the right and left movement with some ifs, and it works fine, now im stuggling with this shooter thing Sad

Author:  Alex C. [ Sun Jan 22, 2012 11:00 am ]
Post subject:  RE:Running something in backround?

lower the increments and delays, that will speed up your program as well as make the collision more detectable

Author:  mirhagk [ Sun Jan 22, 2012 6:33 pm ]
Post subject:  RE:Running something in backround?

Or better yet just use Math.Distance to calculate how far the bullet is from the missile and if it's within 5, then count it as a hit.

Or if you want to be really accurate you can use linear collision detection (think of the lines as the paths the bullet/missile went since the last frame) It will be 100% accurate (even if your game goes a lot slower) but it might be difficult to do.


: