Computer Science Canada

Making a cricle follow the x and y of another

Author:  mobin12 [ Fri Dec 23, 2011 6:49 pm ]
Post subject:  Making a cricle follow the x and y of another

What is it you are trying to achieve?
trying to make the red circle to follow the x and y coordinates of the blue circle, no matter what (including time when the blue circle does not move)


What is the problem you are having?
Can't get the red circle to follow the blue circle around the screen


Describe what you have tried to solve this problem
<Answer Here>


Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>

Turing:


setscreen ("graphics: 800;500")
View.Set ("offscreenonly")
var x : int := 400 % Player x
var y : int := 250 % Player y
var x2 : int := 7 % Red enemy x
var y2 : int := 7 % Red enemy y
var chars : array char of boolean
loop
    drawfilloval (x, y, 10, 10, 55)
    drawfilloval (x2, y2, 7, 7, 41)
    Input.KeyDown (chars)
    if chars ('d') and x < 789 then
        x := x + 1
    end if
    if chars ('a') and x > 10 then
        x := x - 1
    end if
    if chars ('w') and y < 489 then
        y := y + 1
    end if
    if chars ('s') and y > 10 then
        y := y - 1
    end if
    View.Update
    delay (11)
    cls
end loop




Please specify what version of Turing you are using
Turing 4.1.1

Author:  Insectoid [ Fri Dec 23, 2011 6:58 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

Looks to me like you haven't even tried yet. I see no code that uses x2 or y2.

Author:  mobin12 [ Sat Dec 24, 2011 8:36 am ]
Post subject:  Re: Making a cricle follow the x and y of another

i am clueless on how i should approach this problem

Author:  Insectoid [ Sat Dec 24, 2011 9:13 am ]
Post subject:  RE:Making a cricle follow the x and y of another

There are two common ways to approach the problem here.

The easy, ugly way: When do you want the red ball to go up? When do you want it to go down? Left? Right? The answer to that question is literally the code to do it.

The harder, prettier way: Use trig to calculate where the red ball should travel. I suggest you try the easy way first.

Author:  ThatGuyYouLove [ Sat Dec 24, 2011 9:52 am ]
Post subject:  Re: Making a cricle follow the x and y of another

I think the easiest way to do this is to divide the screen into quarters around your enemy
i.e
Blueball(enemy) starts at 7, 7 or x2, y2
then you compare it to yourself and your position, i.e x, y
therefore when you detect for where to move...
code:
if x2 > x then
x2 += 1
elsif x2 < x then
x2 -= 1
end if

if y2 > y then
y2 += 1
elsif y2 < y then
y2 -= 1
end if


So if they are past the enemy on either scale, the enemy moves towards them, and if they are even than they do nothing on that axis.

Author:  Insectoid [ Sat Dec 24, 2011 10:40 am ]
Post subject:  RE:Making a cricle follow the x and y of another

You got that backwards bro. That code will make the red ball run away.

Author:  mobin12 [ Sat Dec 24, 2011 11:21 am ]
Post subject:  Re: Making a cricle follow the x and y of another

I WANT THE REDBALL TO MOVE TO THE POSITION OF THE BLUE, EVEN IF THE BLUE BALL IS NOT MOVING.

Author:  Insectoid [ Sat Dec 24, 2011 12:28 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

You didn't answer the questions I asked.
Quote:
When do you want the red ball to go up? When do you want it to go down? Left? Right?

Author:  Raknarg [ Sat Dec 24, 2011 12:45 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

Here, I'll answer one of those for you.

1: When do you want the red ball to go up?
A: When the blue ball is above it.
Therefore: When the blue is above the red ball, then you want the red ball to go up. Fairly simple.

Author:  mobin12 [ Sat Dec 24, 2011 1:44 pm ]
Post subject:  Re: RE:Making a cricle follow the x and y of another

yes this is exactly my answer

Quote:
Here, I'll answer one of those for you.

1: When do you want the red ball to go up?
A: When the blue ball is above it.
Therefore: When the blue is above the red ball, then you want the red ball to go up. Fairly simple.

and when the BLUE is on right of the RED, move the RED right
when the BLUE is on left of the RED, move the RED left
when the BLUE is on below of the RED, move the RED down
same with diagonals.

Author:  Insectoid [ Sat Dec 24, 2011 2:06 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

I guess now the question is, how do you know when the red ball is above the blue ball?

And diagonals don't matter. They just happen, when you go left and right at the same time. If you do it right, you won't have to write a single line of code for diagonals.

Author:  mobin12 [ Sat Dec 24, 2011 4:00 pm ]
Post subject:  Re: RE:Making a cricle follow the x and y of another

Quote:
I guess now the question is, how do you know when the red ball is above the blue ball?

RIGHT: When x > x2
LEFT: When x < x2
DOWN: When y < y2
UP: When y > y2

Author:  mobin12 [ Sat Dec 24, 2011 4:32 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

This is my attempt
code:

setscreen ("graphics: 800;500")
View.Set ("offscreenonly")
var x : int := 400 % Player x
var y : int := 250 % Player y
var x2 : int := 7 % Red enemy x
var y2 : int := 7 % Red enemy y
var chars : array char of boolean
loop
    drawfilloval (x, y, 10, 10, 55)
    drawfilloval (x2, y2, 7, 7, 41)
    Input.KeyDown (chars)
    if chars ('d') and x < 789 then
        x := x + 2
    end if
    if chars ('a') and x > 10 then
        x := x - 2
    end if
    if chars ('w') and y < 489 then
        y := y + 2
    end if
    if chars ('s') and y > 10 then
        y := y - 2
    end if
    % Attempt on enemy follow
    if x > x2 then
        x2 := x2 + 1
    end if
    if x < x2 then
        x2 := x2 - 1
    end if
    if y > y2 then
        y2 := y2 + 1
    end if
    if y < y2 then
        y2 := y2 - 1
    end if
    View.Update
    delay (15)
    cls
end loop

Author:  Insectoid [ Sat Dec 24, 2011 5:45 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

That looks like it should work!

Protip:
code:
x2 := x2+1

can be written as
code:
x2 += 1


It's the same thing. The 2nd is just nicer to read.

Author:  mobin12 [ Sat Dec 24, 2011 8:57 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

thanks also can you help me with collision dectection

Author:  Raknarg [ Sun Dec 25, 2011 2:47 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

Sure. Have you tried to solve it yet?

Author:  ThatGuyYouLove [ Mon Dec 26, 2011 12:14 pm ]
Post subject:  Re: RE:Making a cricle follow the x and y of another

Insectoid @ Sat Dec 24, 2011 10:40 am wrote:
You got that backwards bro. That code will make the red ball run away.


LOL thanks bro that's actually kinda funny.

For collision detection there are a few ways I can think of off the top of my head.


Spoiler:

the simplest version of detection is just to detect for the center of one object to anywhere on another...
i.e
code:

%Collision detection
%Paste this within your loop to check every time the balls move

if x2 <= (x +RadiusofBlue) and x2 >= (x - RadiusofBlue) then  %broke these up for ease of reading, can be done in one if
if y2 <= (y + RadiusofBlue) and y2 >= (y - RadiusofBlue) then
Collision := true
end if
end if


there must be a more accurate version but the only one I can think of off the top of my head is...
code:

for radiuscount : -RadiusofRed .. RadiusofRed
if (x2 + radiuscount) <= (x +RadiusofBlue) and (x2 + radiuscount) >= (x - RadiusofBlue) then  %broke these up for ease of reading, can be done in one if statement
if (y2 + radiuscount) <= (y + RadiusofBlue) and (y2 + radiuscount) >= (y - RadiusofBlue) then
Collision := true
end if
end if
end for

Checks for if anything on either axis touches.

Author:  Velocity [ Tue Dec 27, 2011 9:41 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

That seems about, right, ddi you get the answer to your question yet? cause i managed to get another solution.

Author:  Velocity [ Tue Dec 27, 2011 9:44 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

@ insectoid that wasnt a protip (dont mean to judge your all holy and honorable proness) that was just standard procedure or another take of it, or less time consuming, or ... ugh this list can go on forever.

Author:  Aange10 [ Tue Dec 27, 2011 10:17 pm ]
Post subject:  Re: RE:Making a cricle follow the x and y of another

Velocity @ 27/12/2011, 8:44 pm wrote:
@ insectoid that wasnt a protip (dont mean to judge your all holy and honorable proness) that was just standard procedure or another take of it, or less time consuming, or ... ugh this list can go on forever.



Actually, it's an operator. Not a procedure. Secondly, if you were smart you'd realize he was being facetious. So,

@Velocity Cool story bro, you mad?

Author:  Insectoid [ Tue Dec 27, 2011 10:47 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

Thanks for having my back Aange10. *brofist*

Line shamelessly stolen from Tony. I think.

Author:  chipanpriest [ Thu Dec 29, 2011 10:06 am ]
Post subject:  Re: Making a cricle follow the x and y of another

Turing:
if x2 < x then
    x2 += 1
elsif x2 > x then
    x2 -= 1
end if

if y2 < y then
    y2 += 1
elsif y2 > y then
    y2 -= 1
end if

this is literally all you need inside your code somewhere for the enemy to follow your guy

the collision code could be something like:
Turing:
if x2 + x2radius >= x - xradius and y2 + y2radius = y - yradius
         and x2 - x2radius <= x + xradius and y2 - y2radius <= y + yradius then
    exit
end if

Author:  Dreadnought [ Thu Dec 29, 2011 5:12 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Most of what is posted above seems to be for rectangles (x+radius > x2-radius stuff). (perhaps with the exception of ThatGuyYouLove's second piece of code).

If we want to check for collision between two circles (which I think you are) there is an easy and "perfect" way to do it. Basically, check the distance between the centers (this is good since we already know where those are). Think of it like drawing a right angled triangle with the hypotenuse being the line between the centers and the other two sides being along the x and y axes. Since we are dealing with circles, we know that the maximum distance that the two centers can be from each other without the circles overlapping is the sum of the radii. Since the distance between the centers is the hypotenuse of our triangle, we just need to check if the hypotenuse is shorter than the sum of the radii. GOGO PYTHAGOREAN THEOREM! (or just use Math.Distance... same thing)

It could look something like this:
Turing:
var x1, y1, rad1 : int % First circle
var x2, y2, rad2 : int % Second circle

% Check for collision
if Math.Distance (x1, y1, x2, y2) < rad1 + rad2 then % This could be <= depending on preference
    put "OMG A COLLISION!"
end if

That's all you need to check collision between circles.

Author:  chipanpriest [ Fri Dec 30, 2011 10:38 am ]
Post subject:  Re: Making a cricle follow the x and y of another

Dreadnought @ Thu Dec 29, 2011 5:12 pm wrote:
GOGO PYTHAGOREAN THEOREM!

lol nice inspector gadget reference

Author:  mobin12 [ Mon Jan 02, 2012 11:09 am ]
Post subject:  Re: Making a cricle follow the x and y of another

Alright guys if you are wondering what all this is for i will show you the other (big piece) of code for my final game:
code:

%Set the screen size
setscreen ("graphics:900;550")
%Anti-flicker command
View.Set ("offscreenonly")

var chars : array char of boolean
var enemy : array 1 .. 3 of int
enemy (1) := 7
enemy (2) := 7
enemy (3) := 1
var mx, my, b : int
var shockwaveValue, player : array 1 .. 4 of int
player (1) := 450
player (2) := 275
player (3) := 54
player (4) := 1
shockwaveValue (3) := 1
shockwaveValue (4) := 0
var space : int := 0
var count : int := 3

loop
    %Draw the player
    if player (4) = 1 then
        drawfilloval (player (1), player (2), 10, 10, player (3))
        drawfilloval (player (1), player (2), 8, 8, player (3) + 1)
    end if
    if enemy (3) = 1 then
        drawfilloval (enemy (1), enemy (2), 7, 7, 41)
    end if
    Input.KeyDown (chars)

    %Player controls
    if chars ('a') and player (1) > 12 then
        player (1) := player (1) - 2
    end if
    if chars ('d') and player (1) < 886 then
        player (1) := player (1) + 2
    end if
    if chars ('w') and player (2) < 514 then
        player (2) := player (2) + 2
    end if
    if chars ('s') and player (2) > 13 then
        player (2) := player (2) - 2
    end if

    % Attempt on enemy follow
    if player (1) > enemy (1) then
        enemy (1) := enemy (1) + 1
    end if
    if player (1) < enemy (1) then
        enemy (1) := enemy (1) - 1
    end if
    if player (2) > enemy (2) then
        enemy (2) := enemy (2) + 1
    end if
    if player (2) < enemy (2) then
        enemy (2) := enemy (2) - 1
    end if

    %Shockwave
    if chars (' ') and count > 0 and space = 0 then
        shockwaveValue (1) := player (1)
        shockwaveValue (2) := player (2)
        shockwaveValue (3) := 1
        shockwaveValue (4) := 1
        count := count - 1
        space := 1
    end if
    if not chars (' ') then
        space := 0
    end if

    %Display amount of shockwaves that are left
    if count = 3 then
        put "Shockwaves:"
        drawoval (133, 538, 7, 7, 39)
        drawoval (133, 538, 8, 8, 39)
        drawoval (154, 538, 7, 7, 39)
        drawoval (154, 538, 8, 8, 39)
        drawoval (175, 538, 7, 7, 39)
        drawoval (175, 538, 8, 8, 39)
    end if
    if count = 2 then
        put "Shockwaves:"
        drawoval (133, 538, 7, 7, 39)
        drawoval (133, 538, 8, 8, 39)
        drawoval (154, 538, 7, 7, 39)
        drawoval (154, 538, 8, 8, 39)
    end if
    if count = 1 then
        put "Shockwaves:"
        drawoval (133, 538, 7, 7, 39)
        drawoval (133, 538, 8, 8, 39)
    end if
    if count = 0 then
        put "Shockwaves:"
    end if

    %Firing the bullets
    mousewhere (mx, my, b)
    if b = 1 then
        drawline (player (1), player (2), mx, my, 43)
    end if

    %Enemy collision with shockwave
    if enemy (1) <= shockwaveValue (3) then
        enemy (3) := 0
    end if
    if enemy (2) <= shockwaveValue (3) then
        enemy (3) := 0
    end if
    %Enemy collision with bullet
    if enemy (1) = mx and b = 1 then
        enemy (3) := 0
    end if
    if enemy (2) = my and b = 1 then
        enemy (3) := 0
    end if
    %Enemy collision with player
    if enemy (1) + 7 <= (player (1) + 12) and enemy (1) + 7 >= (player (1) - 12) and enemy (2) + 7 <= (player (2) + 12) and enemy (2) + 7 >= (player (2) - 12) then
        player (3) := 45
    end if

    %Draw the shockwaves
    if shockwaveValue (4) = 1 then
        drawoval (shockwaveValue (1), shockwaveValue (2), shockwaveValue (3), shockwaveValue (3), 41)
        shockwaveValue (3) := shockwaveValue (3) + 7
        drawoval (shockwaveValue (1), shockwaveValue (2), shockwaveValue (3), shockwaveValue (3), 40)
        shockwaveValue (3) := shockwaveValue (3) + 7
        drawoval (shockwaveValue (1), shockwaveValue (2), shockwaveValue (3), shockwaveValue (3), 39)
        shockwaveValue (3) := shockwaveValue (3) + 7
        if shockwaveValue (3) >= 1000 + 5 then
            shockwaveValue (4) := 0
        end if
    end if

    %Anti-flicker command
    View.Update
    %Slow the program down
    delay (15)
    %Clear the screen for the next loop
    cls
end loop

Author:  mobin12 [ Mon Jan 02, 2012 11:11 am ]
Post subject:  RE:Making a cricle follow the x and y of another

all i need now is a health kind of thing for the player, a background, and maybe some gun sounds

Author:  evildaddy911 [ Mon Jan 02, 2012 4:18 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

health bars are very easy, i usually just write

Turing:
drawfillbox(0,0,health,5,red)

right before the end loop

also, where you display the number of shockwaves left, you output "shockwaves" in every scenario, just write

Turing:
if count>=0 and count<=3 then
put"Shockwaves:"
end if

right before the draw commands

Also, you can save a few lines there by using "elsif" instead of
"end if
if
", because the if statements are dealing with a single value being a specific number

Author:  mobin12 [ Tue Jan 03, 2012 12:09 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

is 'health' another variable

Author:  Dreadnought [ Tue Jan 03, 2012 2:27 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Yes, in his case health would be an integer variable representing both health and length (in pixels) of the health bar.

Author:  evildaddy911 [ Tue Jan 03, 2012 3:17 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

if your health variable is too large, the you can shrink the bar by using div,

Turing:
drawfillbox(0, 0, health div 10, 5, red)


div just means divide with out remainder ( mod ) or decimals ( / ), mostly used when you need an integer

if you want it to look a bit better, then use

Turing:
drawbox(0, 0, max_health div 10, 5 red)
drawfillbox(0, 0, health div 10, 5, red)


max_health is another variable too.

backgrounds aren't too difficult, use Photoshop, fireworks, Google images, paint etc. to generate an image (make sure to save it as .jpg or .bmp), then,

Turing:
var background : int := Pic.FileNew ("[file name and extension]")

Pic.Draw (background, 0, 0, picMerge)


which draws your picture with the bottom left corner at (0,0)

Author:  mobin12 [ Tue Jan 03, 2012 8:12 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

so for the enemy how do i make it disappear forever? 'cause i got it to disappear but its still there u just cant see it


also does the background have to be in a zip along with the code?

Author:  Dreadnought [ Tue Jan 03, 2012 9:13 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

What exactly do you mean when you say "disappear forever"? Because disappearing and not seeing it are basically the same thing in my mind.

For your second question, any picture or sound files used by the program must be kept in the same folder (or at least on the same filepath) relative to the program in order to run the program. Making a zipped folder containing everything is a good way to keep everything as a package.

Author:  Raknarg [ Wed Jan 04, 2012 12:27 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

There is no way to destroy the enemy; What you can do is make it so the program, aftger the enemy is hit, no longer intereacts witht eh enemy.

When I say this, it means that you have something keeping track of it. If the enemy is alive, then move him/shoot bullets/drawing/etc. If enemy is dead, then don't do any of those things. Something like this

Turing:

if enemyLive then
     do_stuff ()
end if


Thats the basic idea

Author:  mobin12 [ Fri Jan 06, 2012 7:27 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

alright so how would i make an intro and then the player would hit 'enter' and then the game would start

Author:  Dreadnought [ Fri Jan 06, 2012 8:55 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Well, you have to make an intro screen with graphics obviously (that's not your problem I think). Next you need to check if the user pressed enter. You may be using a loop if the intro screen is animated. In that case you should be able to check for key strokes in the same way you check for WASD and space in you game (using Input.KeyDown). You can also look at the other input functions in the documentation.

Author:  Raknarg [ Fri Jan 06, 2012 11:07 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

Fairly simple idea:

Turing:

loop
     intro()
     exit when key (KEY_ENTER)
end loop

loop
     game()
end loop


something like that

Author:  mobin12 [ Sun Jan 08, 2012 6:15 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

ok so i did that know i tried putting the 'intructions loop' in between the 'intro loop' and the 'game loop' but it never showed the intructions pic that i made

Author:  Dreadnought [ Sun Jan 08, 2012 6:51 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Was it erased immediately by the game?

Author:  mobin12 [ Mon Jan 09, 2012 10:36 am ]
Post subject:  RE:Making a cricle follow the x and y of another

no once i clicked to go to the instrucions it would still show the 'intro pic' and then i would have to click a bit lower to start the game but only i know where to click
if other people play they would get confused

Author:  Dreadnought [ Mon Jan 09, 2012 12:06 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Well, without knowing what your code looks like its hard to be very helpful. I suppose my second guess would be that maybe you forgot to put a View.Update line.

Author:  mobin12 [ Mon Jan 09, 2012 4:20 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

well actually i tried the 'View.Update' but it didn't work out so well. But anyways here is my code.
code:

setscreen ("graphics:900;550")
%Anti-flicker command
View.Set ("offscreenonly")

var chars : array char of boolean
var enemy, player : array 1 .. 3 of int
enemy (1) := 15
enemy (2) := 15
enemy (3) := 1
player (1) := 450
player (2) := 275
player (3) := 1
var mx, my, b : int
var shockwaveValue : array 1 .. 4 of int
shockwaveValue (3) := 1
shockwaveValue (4) := 0
var space : int := 0
var count : int := 3
var health : int := 215
var intro : int := Pic.FileNew ("Game-Intro.jpg")
var instructions : int := Pic.FileNew ("Game-Instructions.jpg")
var background : int := Pic.FileNew ("Game-Background.jpg")
var bullet :  array 1..2 of int
bullet(1) := 50
bullet(2) := 0

%THE INTRO
loop
    Pic.Draw (intro, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 288 and mx < 634 and my > 185 and my < 234 and b = 1
end loop

%THE INSTRUCTIONS
loop
    Pic.Draw (instructions, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 242 and mx < 694 and my > 104 and my < 170 and b = 1
end loop

%THE GAME
loop
    %Draw the background for the game
    Pic.Draw (background, 0, 0, picMerge)
    %Draw the player
    if player (3) = 1 then
        drawfilloval (player (1), player (2), 10, 10, 54)
        drawfilloval (player (1), player (2), 8, 8, 55)
    end if
    if enemy (3) = 1 then
        drawfilloval (enemy (1), enemy (2), 7, 7, 41)
    elsif enemy (3) = 0 then
        enemy (1) := 15
        enemy (2) := 15
        drawfilloval (enemy (1), enemy (2), 7, 7, 41)
        enemy (3) := 1
    end if

    Input.KeyDown (chars)

    %Player controls
    if chars (KEY_LEFT_ARROW) and player (1) > 48 then
        player (1) := player (1) - 2
    end if
    if chars (KEY_RIGHT_ARROW) and player (1) < 851 then
        player (1) := player (1) + 2
    end if
    if chars (KEY_UP_ARROW) and player (2) < 472 then
        player (2) := player (2) + 2
    end if
    if chars (KEY_DOWN_ARROW) and player (2) > 49 then
        player (2) := player (2) - 2
    end if

    % Attempt on enemy follow
    if player (1) > enemy (1) then
        enemy (1) := enemy (1) + 1
    end if
    if player (1) < enemy (1) then
        enemy (1) := enemy (1) - 1
    end if
    if player (2) > enemy (2) then
        enemy (2) := enemy (2) + 1
    end if
    if player (2) < enemy (2) then
        enemy (2) := enemy (2) - 1
    end if

    %Shockwave
    if chars (KEY_SHIFT) and count > 0 and space = 0 then
        shockwaveValue (1) := player (1)
        shockwaveValue (2) := player (2)
        shockwaveValue (3) := 1
        shockwaveValue (4) := 1
        count := count - 1
        space := 1
    end if
    if not chars (KEY_SHIFT) then
        space := 0
    end if

    %Display amount of shockwaves that are left
    if count = 3 then
        drawoval (198, 538, 7, 7, 39)
        drawoval (198, 538, 8, 8, 39)
        drawoval (222, 538, 7, 7, 39)
        drawoval (222, 538, 8, 8, 39)
        drawoval (245, 538, 7, 7, 39)
        drawoval (245, 538, 8, 8, 39)
    end if
    if count = 2 then
        drawoval (198, 538, 7, 7, 39)
        drawoval (198, 538, 8, 8, 39)
        drawoval (222, 538, 7, 7, 39)
        drawoval (222, 538, 8, 8, 39)
    end if
    if count = 1 then
        drawoval (198, 538, 7, 7, 39)
        drawoval (198, 538, 8, 8, 39)
    end if
    if count = 0 then
    end if

    %Firing the bullets
    mousewhere (mx, my, b)
    if b = 1 and bullet(2) = 0 then
        drawline (player (1), player (2), mx, my, 40)
    end if

    %Enemy collision with shockwave
    if enemy (1) <= shockwaveValue (3) then
        enemy (3) := 0
    end if
    if enemy (2) <= shockwaveValue (3) then
        enemy (3) := 0
    end if
    %Enemy collision with bullet
    if mx = (enemy (1) + 7) and b = 1 and bullet(2) = 0 then
        enemy (3) := 0
    end if
    if my = (enemy (2) + 7) and b = 1 and bullet(2) = 0 then
        enemy (3) := 0
    end if
    %Enemy collision with player and player health
    drawfillbox (395, 528, 394 + health, 542, 46)
    if enemy (3) = 1 and enemy (1) - 7 <= (player (1) + 12) and enemy (1) + 7 >= (player (1) - 12) and enemy (2) - 7 <= (player (2) + 12) and enemy (2) + 7 >= (player (2) - 12) and health >= 0
            then
        health := health - 1
    end if
    if health = 0 then
        player (3) := 0
    end if

    %Draw the shockwaves
    if shockwaveValue (4) = 1 then
        drawoval (shockwaveValue (1), shockwaveValue (2), shockwaveValue (3), shockwaveValue (3), 41)
        shockwaveValue (3) := shockwaveValue (3) + 7
        drawoval (shockwaveValue (1), shockwaveValue (2), shockwaveValue (3), shockwaveValue (3), 40)
        shockwaveValue (3) := shockwaveValue (3) + 7
        drawoval (shockwaveValue (1), shockwaveValue (2), shockwaveValue (3), shockwaveValue (3), 39)
        shockwaveValue (3) := shockwaveValue (3) + 7
        if shockwaveValue (3) >= 1000 + 5 then
            shockwaveValue (4) := 0
        end if
    end if
   
    bullet(2) := bullet(2) + 1
    if bullet(2) >= bullet(1) then
        bullet(2) := 0
    end if

    %Anti-flicker command
    View.Update
    %Slow the program down
    Time.Delay (8)
    %Clear the screen for the next loop
    cls
    exit when player (3) = 0
end loop

Author:  mobin12 [ Mon Jan 09, 2012 4:25 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Here is the part i need help with. The switch from the intro to the instructions.
code:

%THE INTRO
loop
    Pic.Draw (intro, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 288 and mx < 634 and my > 185 and my < 234 and b = 1
end loop

%THE INSTRUCTIONS
loop
    Pic.Draw (instructions, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 242 and mx < 694 and my > 104 and my < 170 and b = 1
end loop

Author:  Dreadnought [ Mon Jan 09, 2012 6:21 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

You have to understand what your code is actually doing.
Turing:
View.Set ("offscreenonly")

This stops the onscreen window (the one you see) from receiving output, instead, all output is only sent to an offscreen window (a sort of virtual window in the computer's memory). However, when you call View.Update, the offscreen window is copied to the onscreen window.

http://compsci.ca/holtsoft/doc/view_update.html wrote:
This can be used to provide smooth, flicker-free animation. Animated objects flicker when the object being animated disappears from the onscreen window for a period of time. By using View.Set ("offscreenonly") / View.Update, the onscreen window is never blank. Instead, the offscreen window drawn over top off the on screen window, replacing it. This means that the on-screen window is never blanked out, eliminating the flickering found in the animation.


This means that if you want to see something, you must call View.Update. In your case, the intro picture is drawn to the onscreen window because it is the first thing ever drawn to the Turing window (this is a special case). The instruction picture is drawn to the offscreen window but not the onscreen one (thus it doesn't show up). Finally, when the game starts, the game loop draw's over the instruction picture in the offscreen window and calls View.update, meaning, the instruction picture is never drawn to the onscreen window.

Hope this has cleared up the problem.

Author:  mobin12 [ Mon Jan 09, 2012 6:39 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

so where am i suppposed to put View.Update on the 'intro code' or the 'instructions code'?

Author:  Dreadnought [ Mon Jan 09, 2012 7:20 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

mobin12 wrote:

it never showed the intructions pic that i made

Dreadnought wrote:

Turing:
View.Set ("offscreenonly")

This stops the onscreen window (the one you see) from receiving outputt, instead, all output is only sent to an offscreen window

This means that if you want to see something, you must call View.Update.


Where do you draw stuff that you want to see?
If you want this stuff to be visible, should you update the screen before or after you draw said stuff?

Author:  mobin12 [ Wed Jan 11, 2012 8:53 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Alright guys, thank you very much with all your help
So here's my way of thanking you guys (MY CODE):
code:

%Set the screen size
setscreen ("graphics:900;550,nobuttonbar,offscreenonly")

var chars : array char of boolean
var enemy, player : array 1 .. 3 of int
enemy (1) := 15
enemy (2) := 15
enemy (3) := 1
player (1) := 450
player (2) := 275
player (3) := 1
var mx, my, b : int
var shockwave : array 1 .. 4 of int
shockwave (3) := 1
shockwave (4) := 0
var space : int := 0
var count : int := 3
var health : int := 215
var Intro : int := Pic.FileNew ("Game-Intro.jpg")
var Instructions : int := Pic.FileNew ("Game-Instructions.jpg")
var Background : int := Pic.FileNew ("Game-Background.jpg")
var End : int := Pic.FileNew ("Game-End.jpg")
var font : int := Font.New ("DigifaceWide:46")
var font1 : int := Font.New ("Ethnocentric:13")
var score : int := 0
var s : string := ""

%THE INTRO
loop
    Pic.Draw (Intro, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 288 and mx < 634 and my > 185 and my < 234 and b = 1
    View.Update
end loop

%THE INSTRUCTIONS
loop
    Pic.Draw (Instructions, 0, 0, picMerge)
    mousewhere (mx, my, b)
    exit when mx > 242 and mx < 694 and my > 104 and my < 170 and b = 1
    View.Update
    cls
end loop

%THE GAME
loop
    loop
        %Draw the Background for the game
        Pic.Draw (Background, 0, 0, picMerge)
       
        s:=intstr(score)
        Font.Draw ("score: ", 0, 507, font1, black)
        Font.Draw (s, 94, 507, font1, black)
       
        %Draw the player
        if player (3) = 1 then
            drawfilloval (player (1), player (2), 10, 10, 54)
            drawfilloval (player (1), player (2), 8, 8, 55)
        end if
        if enemy (3) = 1 then
            drawfilloval (enemy (1), enemy (2), 7, 7, 41)
        elsif enemy (3) = 0 then
            enemy (1) := 15
            enemy (2) := 15
            drawfilloval (enemy (1), enemy (2), 7, 7, 41)
            enemy (3) := 1
        end if

        Input.KeyDown (chars)

        %Player controls
        if chars ('a') and player (1) > 48 then
            player (1) := player (1) - 2
        end if
        if chars ('d') and player (1) < 851 then
            player (1) := player (1) + 2
        end if
        if chars ('w') and player (2) < 472 then
            player (2) := player (2) + 2
        end if
        if chars ('s') and player (2) > 49 then
            player (2) := player (2) - 2
        end if

        % Attempt on enemy follow
        if player (1) > enemy (1) then
            enemy (1) := enemy (1) + 1
        end if
        if player (1) < enemy (1) then
            enemy (1) := enemy (1) - 1
        end if
        if player (2) > enemy (2) then
            enemy (2) := enemy (2) + 1
        end if
        if player (2) < enemy (2) then
            enemy (2) := enemy (2) - 1
        end if

        %Shockwave
        if chars (' ') and count > 0 and space = 0 then
            shockwave (1) := player (1)
            shockwave (2) := player (2)
            shockwave (3) := 1
            shockwave (4) := 1
            count := count - 1
            space := 1
        end if
        if not chars (' ') then
            space := 0
        end if

        %Display amount of shockwaves that are left
        if count = 3 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
            drawoval (222, 538, 7, 7, 39)
            drawoval (222, 538, 8, 8, 39)
            drawoval (245, 538, 7, 7, 39)
            drawoval (245, 538, 8, 8, 39)
        end if
        if count = 2 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
            drawoval (222, 538, 7, 7, 39)
            drawoval (222, 538, 8, 8, 39)
        end if
        if count = 1 then
            drawoval (198, 538, 7, 7, 39)
            drawoval (198, 538, 8, 8, 39)
        end if
        if count = 0 then
        end if

        %Firing the bullets
        mousewhere (mx, my, b)
        if b = 1 then
            drawline (player (1), player (2), mx, my, 40)
        end if

        %Enemy collision with shockwave
        if round (sqrt (((player (1) - enemy (1)) ** 2) + (player (2) - enemy (2)) ** 2)) <= shockwave (3) and shockwave (4) = 1 and enemy (3) = 1 and round (sqrt (((enemy (1) - player (1)) ** 2) + (enemy (2) - player (2)) ** 2)) <= shockwave (3) and shockwave (4) = 1 and enemy (3) = 1 and score <= 99999 then
            enemy (3) := 0
            score := score + 5
        end if
       
        %Enemy collision with bullet
        if mx <= (enemy (1) + 7) and mx >= (enemy (1) - 7) and b = 1 and my <= (enemy (2) + 7) and my >= (enemy (2) - 7) and b = 1 and score <= 99999 then
            enemy (3) := 0
            score := score + 10
        end if
       
        %Enemy collision with player and player health
        drawfillbox (395, 528, 394 + health, 542, 46)
        if enemy (3) = 1 and enemy (1) - 7 <= (player (1) + 12) and enemy (1) + 7 >= (player (1) - 12) and enemy (2) - 7 <= (player (2) + 12) and enemy (2) + 7 >= (player (2) - 12) and health >= 1 then
            health := health - 1
            score := score - 2
        end if
        if health = 0 then
            player (3) := 0
        end if

        %Draw the shockwaves
        if shockwave (4) = 1 then
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 41)
            shockwave (3) := shockwave (3) + 3
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 40)
            shockwave (3) := shockwave (3) + 3
            drawoval (shockwave (1), shockwave (2), shockwave (3), shockwave (3), 39)
            shockwave (3) := shockwave (3) + 3
            if shockwave (3) >= 1000 + 5 then
                shockwave (4) := 0
            end if
        end if
       
        %Anti-flicker command
        View.Update
       
        %Slow program down
        Time.Delay (8)
       
        %Clear screen for the next loop
        cls
        exit when player (3) = 0
    end loop
   
    %THE END
    loop
        s:=intstr(score)
        Pic.Draw (End, 0, 0, picMerge)
        Font.Draw (s, 481, 355, font, white)
        View.Update
        mousewhere (mx, my, b)
       
        %Restart the game if 'TRY AGAIN' is clicked
        if mx > 216 and mx < 389 and my > 183 and my < 271 and b = 1 then
            %Set the variables
            enemy (1) := 15
            enemy (2) := 15
            enemy (3) := 1
            player (1) := 450
            player (2) := 275
            player (3) := 1
            count := 3
            health := 215
            score := 0
            exit
        end if
       
        %Close the game if 'EXIT' is clicked
        if mx > 522 and mx < 692 and my > 200 and my < 257 and b = 1 then
            Window.Close (defWinID)
        end if
    end loop
end loop

also it would be very great if anyone could help me with: make a lot more enemies appear in different spots of the ENEMY BAY. Rather then one enemy in the same spot.
Thanks a lot guys. Very Happy

Author:  Dreadnought [ Wed Jan 11, 2012 9:34 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Nice game.

If you want to have enemies spawn in different locations try using Rand.Int (min, max). You can also check if the random spawn location satisfies certain conditions, (for instance, not too close to the player).

If you want multiple enemies, you should create an array of enemies (enemy data I mean). Then you cycle through each one when checking for collision.

Author:  mobin12 [ Thu Jan 12, 2012 10:22 am ]
Post subject:  RE:Making a cricle follow the x and y of another

but if i do randint the enemy will appear outside the 'ENEMY BAY'.

Author:  Dreadnought [ Thu Jan 12, 2012 3:59 pm ]
Post subject:  Re: Making a cricle follow the x and y of another

Like I said you might have to check if the new position is allowed. Alternately, it seems your "enemy bay" is just a frame around the playing area (I think but I don't have the background pictures), that's 4 rectangles. All you have to do is randomly select one of the four rectangle and then randomly select a position within the chosen rectangle.

Author:  Alex C. [ Thu Jan 12, 2012 4:05 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

um try this tutorial: http://compsci.ca/v3/viewtopic.php?t=8808
this has alot of links to basic programming

Author:  mobin12 [ Tue Jan 17, 2012 4:17 pm ]
Post subject:  RE:Making a cricle follow the x and y of another

@Alex C.
this does not help at all


: