Computer Science Canada

Lots and lots of errors...

Author:  Flikerator [ Thu Feb 10, 2005 6:22 pm ]
Post subject:  Lots and lots of errors...

Okay ima make a list of errors that I have.
(NOTE you will have to download the picture)

code:

var background : int := Pic.FileNew ("Background.jpg")
var x, y : int := 200
var ch : string (1)
var c, v, z : int := 0

View.Set ("graphics")

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

procedure movement
    loop
        getch (ch)
        if ch = "w" or ch = "W" then
            y := y + 5
        elsif ch = "s" or ch = "S" then
            y := y - 5
        elsif ch = "d" or ch = "D" then
            x := x + 5
        elsif ch = "a" or ch = "A" then
            x := x - 5
        end if


        Pic.Draw (background, 0, 0, picCopy)
        Draw.Oval (x, y, 15, 15, red)
        Draw.FillOval (x, y, 14, 14, brightred)
        View.Update
    end loop
end movement
process gun
    loop
        Mouse.Where (c, v, z)
        Draw.Line (x, y, c, v, red)
    end loop
end gun
fork gun
movement


First of all Ill tell you what I want it to do. Have the little cicle move around (Later resemble a person) and have him face any direction that the mouse is pointing.

I got the circle to move with Getch. It flickers.
The gun faces the way it is supposed to, but it goes where the mouse is, and overlaps the person (I can fix the overlap).

If you can help me fix any or all of these it will be greatly appreciated

Author:  Bacchus [ Thu Feb 10, 2005 7:26 pm ]
Post subject: 

code:
var x, y : int := 200
var ch : array char of boolean
var c, v, z : int := 0

View.Set ("graphics,offscreenonly") %forgot to put offscreenonly
%ddint want to get the background sooo... took it out

procedure movement
    loop
        cls
        Input.KeyDown (ch) %no waiting and blibking light yuk :P
        if ch ('w') then
            y += 5
        elsif ch ('s') then
            y -= 5
        elsif ch ('d') then
            x += 5
        elsif ch ('a') then
            x -= 5
        end if

        Mouse.Where (c, v, z) %processes r evil
        if z~=0 then
        Draw.Line (x, y, c, v, red)
        end if

        Draw.FillOval (x, y, 14, 14, brightred)
        Draw.Oval (x, y, 14, 14, red)
        View.Update
        delay(10)
    end loop
end movement

movement
not sure if that how u wanted... but hey some fixed

Author:  Flikerator [ Thu Feb 10, 2005 8:38 pm ]
Post subject: 

Sweet. Thanks for all the help. Its so much smoother and it doesn't blink like crazy thanks. Now I just have to make a bunch of different looking guns in turing (Shotgun, semi, auto, sniper) and have them able to rotate towards the mouse ^^

Ill have to work on that tommorow though cause I dun have turing on this comp (Checked it when I still have other comp).

Thanks again. (Its for Zombie Mass'Acres)

Author:  Flikerator [ Fri Feb 11, 2005 4:14 pm ]
Post subject:  New problem

My gun is nearly complete! But before I finish it to fire in any direction I need a little help.

I want the bullets to stop flickering, and I want there to be delay between firing. I was thinking that mabey putting in a gun sound that plays out before you can do anything except move. I dunno I need some help to stop the flickering and put some delay between firing. You will probably want to download the background because it symbolizes the ground which I wil have in my game. I could have just erased the bullet with white instead but I have a multicoloured background so its a bit different.

code:

var x, y : int := 200
var ch : array char of boolean
var c, v, z : int := 0
var background : int := Pic.FileNew ("Pictures/Background.jpg")
View.Set ("graphics:640,439,offscreenonly")

process bullet (xx, yy : int)
    if c > x then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx + 15 + i, yy, 5, 1, yellow)
            delay (10)
            View.Update
        end for
    end if
end bullet

procedure movement
    loop
        Pic.Draw (background, 0, 0, picCopy)
        Input.KeyDown (ch)
        if ch ('w') then
            if y < maxy - 20 then
                y += 5
            end if
        elsif ch ('s') then
            if y > 20 then
                y -= 5
            end if
        elsif ch ('d') then
            if x < maxx - 20 then
                x += 5
            end if
        elsif ch ('a') then
            if x > 20 then
                x -= 5
            end if
        end if

        Mouse.Where (c, v, z)
        Draw.Line (x, y, c, v, yellow)

        if z = 1 then
            fork bullet (x, y)
        end if

        Draw.FillOval (x, y, 14, 14, brightred)
        Draw.Oval (x, y, 14, 14, red)
        View.Update
        delay (20)
    end loop
end movement

movement

Author:  Cervantes [ Fri Feb 11, 2005 4:31 pm ]
Post subject: 

Don't use a process. Especially if it means having two or more View.Updates.

Author:  Flikerator [ Fri Feb 11, 2005 4:32 pm ]
Post subject: 

What else can I do? If I put it in the procedure thing I got going on then the bullet goes its path and then I can move again.


UPDATED
-----------
code:

var x, y : int := 200
var ch : array char of boolean
var c, v, z : int := 0
var background : int := Pic.FileNew ("Pictures/Background.jpg")
View.Set ("graphics:640,439,offscreenonly")

process bullet (xx, yy : int)
    if c > x and y + 10 > v and y - 10 < v then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx + 15 + i, yy, 5, 1, yellow)
            delay (10)
            View.Update
        end for
    elsif c < x and y + 10 > v and y - 10 < v then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx - 15 - i, yy, 5, 1, yellow)
            delay (10)
            View.Update
        end for
    elsif v > y and x + 10 > c and x - 10 < c then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx, yy + 15 + i, 1, 5, yellow)
            delay (10)
            View.Update
        end for
    elsif v < y and x + 10 > c and x - 10 < c then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx, yy - 15 - i, 1, 5, yellow)
            delay (10)
            View.Update
        end for
    end if
end bullet

procedure movement
    loop
        Pic.Draw (background, 0, 0, picCopy)
        Input.KeyDown (ch)
        if ch ('w') then
            if y < maxy - 20 then
                y += 5
            end if
        elsif ch ('s') then
            if y > 20 then
                y -= 5
            end if
        elsif ch ('d') then
            if x < maxx - 20 then
                x += 5
            end if
        elsif ch ('a') then
            if x > 20 then
                x -= 5
            end if
        end if

        Mouse.Where (c, v, z)
        Draw.Line (x, y, c, v, yellow)

        if z = 1 then
            fork bullet (x, y)
        end if

        Draw.FillOval (x, y, 14, 14, brightred)
        Draw.Oval (x, y, 14, 14, red)
        View.Update
        delay (20)
    end loop
end movement

movement

Author:  Cervantes [ Fri Feb 11, 2005 6:12 pm ]
Post subject: 

Flikerator wrote:

What else can I do? If I put it in the procedure thing I got going on then the bullet goes its path and then I can move again.

Make the bullet an object (or emulate an object) and update it based on its own properties.
Learning records would be good for this. Check the tutorial section.
-Cervantes

Author:  Flikerator [ Fri Feb 11, 2005 6:49 pm ]
Post subject: 

Search which tutorial and what would it fix?


UPDATE CODE - Notice that you can move with the numpad including digonal. You can currently shoot in 4 direction with a small degree of give (Ei 10 pixels either direction)

You have to click to fire also.
code:

var x, y : int := 200
var ch : array char of boolean
var c, v, z : int := 0
var background : int := Pic.FileNew ("Pictures/Background.jpg")
View.Set ("graphics:640,439,offscreenonly")

process bullet (xx, yy : int)
    if c > x and y + 10 > v and y - 10 < v then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx + 15 + i, yy, 5, 1, yellow)       %90*
            delay (10)
            View.Update
        end for
    elsif c < x and y + 10 > v and y - 10 < v then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx - 15 - i, yy, 5, 1, yellow)       %270*
            delay (10)
            View.Update
        end for
    elsif v > y and x + 10 > c and x - 10 < c then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx, yy + 15 + i, 1, 5, yellow)       %360*
            delay (10)
            View.Update
        end for
    elsif v < y and x + 10 > c and x - 10 < c then
        for i : 1 .. 400 by 4
            Draw.FillOval (xx, yy - 15 - i, 1, 5, yellow)       %180*
            delay (10)
            View.Update
        end for
    end if
end bullet

procedure movement
    loop
        Pic.Draw (background, 0, 0, picCopy)
        Input.KeyDown (ch)
        if ch ('w') or ch ('8') then
            if y < maxy - 20 then
                y += 5
            end if
        elsif ch ('s') or ch ('2') then
            if y > 20 then
                y -= 5
            end if
        elsif ch ('d') or ch ('6') then
            if x < maxx - 20 then
                x += 5
            end if
        elsif ch ('a') or ch ('4') then
            if x > 20 then
                x -= 5
            end if
        elsif ch ('7') then
            if y < maxy - 20 and x > 20 then
                y += 2
                x -= 2
            end if
        elsif ch ('9') then
            if y < maxy - 20 and x < maxx - 20 then
                y += 2
                x += 2
            end if
        elsif ch ('3') then
            if y > 20 and x < maxx - 20 then
                y -= 2
                x += 2
            end if
        elsif ch ('1') then
            if y > 20 and x > 20 then
                x -= 2
                y -= 2
            end if
        end if

        Mouse.Where (c, v, z)
        Draw.Line (x, y, c, v, yellow)

        if z = 1 then
            fork bullet (x, y)
        end if

        Draw.FillOval (x, y, 14, 14, brightred)
        Draw.Oval (x, y, 14, 14, red)
        View.Update
        delay (20)
    end loop
end movement

movement


Things I need to work:
- Bullets flickering
- Delay BETWEEN firing bullets. That more then the flickering.
- The line goes all the way to the mouse. I need it to go only say, 10 pixles towards it.

Author:  Cervantes [ Fri Feb 11, 2005 6:58 pm ]
Post subject: 

Flikerator wrote:

Search which tutorial

Cervantes wrote:

Learning records would be good for this. Check the tutorial section.


flikerator wrote:

and what would it fix?

Cervantes wrote:

Don't use a process.

To elaborate, it will fix the whole needing-to-use-a-process crap.

Also, I'm not sure if you WANT to only be able to shoot in four directions, but you could easily make your bullet fire at any angle if you make the bullet an object and don't use processes.

Author:  Flikerator [ Fri Feb 11, 2005 7:02 pm ]
Post subject: 

Alright thanks I just have to find the tutorial then ill test it out. Thanks for the help btw.

EDIT - I checked out the tutorial called "records" and I didn't understand it. Could you give me an example different from the one found there. I looked in turing reference and I don't understand it eiteher, well it gets an error so >.<

Author:  Cervantes [ Fri Feb 11, 2005 7:50 pm ]
Post subject: 

Records are very simple. Types must be a little bit more difficult.
Let's just deal with records. We don't need types for this.

if we declare a variable, bullet, it can only ever have one value. That limits us, because we need information about the bullets x and y position, as well as its x and y velocity.
So, to solve this, we make a record.

code:

var bullet :
  record
    x : real
    y : real
    vx : real
    vy : real
  end record

Now, we have our variable, "bullet", but we can store much more information with it.

It's pretty simple. If you don't get it, come on IRC. compsci.ca on afternet. You can always click Hikaru's link for simplicity. Smile Or you can MSN me (check the msn icon).

-Cervantes

Author:  Flikerator [ Fri Feb 11, 2005 8:17 pm ]
Post subject: 

Okay that sounds a little better. But how do I give them values and use them to move the bullet? (I added you to msn, if it didnt work then add me at Doubleultranova@hotmail.com )

Thanks for all the help : D Im learning lots!

Author:  Bacchus [ Sat Feb 12, 2005 12:28 am ]
Post subject: 

to give them values you would do something like:
code:
var bullet:
    record
        x,y,vx,vy:real
    end record

bullet.x:=10 %notice the . in there
bullet.y:=10
bullet.vx:=2.5
bullet.vy:=2.5

View.Set ("offscreenonly")

loop
    cls
    bullet.x+=bullet.vx
    bullet.y+=bullet.vy

    drawfilloval (round(bullet.x),round(bullet.y),5,5,2) %<-- the round is to make the real value an int value
    View.Update
    delay(10)
end loop
im not that good at explanations Confused

Author:  Flikerator [ Sat Feb 12, 2005 3:15 pm ]
Post subject: 

Alright now I finnaly understand records BUT

If I put that in then it does the animation of the bullet and doesnt let me do anything untill its done. I would have to put it into a process, which eliminates the whole idea behind me making the bullet a record...lolz

I also need to put a delay between firing each bullet. Which Im thinking you have to press the mouse down and then when it goes up it fires again? I unno thats why I need help ^^

Thanks for that Bacchus cause now I know how to work records completely (as far as I know.)

Author:  Bacchus [ Sat Feb 12, 2005 3:56 pm ]
Post subject: 

no prob. but still no processes. they suk and r evil
try adding something like this in ur game
code:
var bullet
    record
        x,y,vx,vy:int
        fire:boolean
    end record

bullet.fire:=false

var mx,my,mb:int
loop
    cls
    Mouse.Where(mx,my,mb)
    if mb~=0 & ~bullet.fire then %with boolean u can just put variable name for true or a ~ in front for false
        bullet.fire:=true
        bullet.x:=10 %or ur starting point for byullet
        bullet.y:=10 %same
    elsif bullet.fire then
        bullet.x+=bullet.vx
        bullet.y+=bullet.vy
    end if
    View.Update % yes i kno im missing other bit, just an example
end loop

Author:  Cervantes [ Sat Feb 12, 2005 4:18 pm ]
Post subject: 

Bacchus, you're missing a bullet.fire := false somewhere inside your loop. Wink

Flikerator, it might be worth your while to check out the Flexible Array Tutorial. It will give you an example of creating a bullet, firing it off at any direction, and limiting the firing with a cooldown.
The cooldown down aspect is a simple function:
Turing:

var timeLast := 0
function cooldown (timeDelay : int) : boolean
    if Time.Elapsed - timeLast >= timeDelay then
        result true
    end if
    result false
end cooldown

loop %main loop
    if cooldown (300) then
        %do stuff
        timeLast := Time.Elapsed
    end if
end loop


Hope that helps,
-Cervantes

Author:  Flikerator [ Sat Feb 12, 2005 5:24 pm ]
Post subject: 

I was reading through it (Learning a lot thanks Cervantes) and I found this;

code:

var winID := Window.Open ("graphics:500;500,nobuttonbar,offscreenonly")
var player :
    record
        x, y : real
        dir : real
        forward_speed, backward_speed : int
        life : int
        radius : int
    end record

player.x := 100
player.y := 100
player.dir := 45
player.forward_speed := 2
player.backward_speed := 1
player.life := 100
player.radius := 10

var bullet : flexible array 1 .. 0 of
    record
        startx, starty : real
        x, y, vx, vy : real
        dir : real
    end record

const bulletVelocity := 10


var keys : array char of boolean

var timeLast := 0
function cooldown (timeDelay : int) : boolean
    if Time.Elapsed - timeLast >= timeDelay then
        result true
    end if
    result false
end cooldown

procedure playerControls
    if keys (KEY_RIGHT_ARROW) then
        if player.dir <= 0 then
            player.dir += 360
        end if
        player.dir -= 2
    end if
    if keys (KEY_LEFT_ARROW) then
        if player.dir >= 360 then
            player.dir -= 360
        end if
        player.dir += 2
    end if
    if keys (KEY_UP_ARROW) then
        player.x += cosd (player.dir) * player.forward_speed
        player.y += sind (player.dir) * player.forward_speed
    end if
    if keys (KEY_DOWN_ARROW) then
        player.x -= cosd (player.dir) * player.backward_speed
        player.y -= sind (player.dir) * player.backward_speed
    end if
    if keys (KEY_SHIFT) then
        if cooldown (300) then
            new bullet, upper (bullet) + 1
            bullet (upper (bullet)).startx := player.x + (cosd (player.dir) * player.radius)
            bullet (upper (bullet)).starty := player.y + (sind (player.dir) * player.radius)
            bullet (upper (bullet)).x := bullet (upper (bullet)).startx
            bullet (upper (bullet)).y := bullet (upper (bullet)).starty
            bullet (upper (bullet)).dir := player.dir
            bullet (upper (bullet)).vx := cosd (bullet (upper (bullet)).dir) * bulletVelocity
            bullet (upper (bullet)).vy := sind (bullet (upper (bullet)).dir) * bulletVelocity
            timeLast := Time.Elapsed
        end if
    end if
end playerControls
procedure updateBullet
    for i : 1 .. upper (bullet)
        if Math.Distance (bullet (i).startx, bullet (i).starty, bullet (i).x, bullet (i).y) >= 300 then
            for k : i + 1 .. upper (bullet)
                bullet (k - 1) := bullet (k)
            end for
            new bullet, upper (bullet) - 1
            exit %problematic
        end if

        bullet (i).x += bullet (i).vx
        bullet (i).y += bullet (i).vy

        Draw.FillOval (round (bullet (i).x), round (bullet (i).y), 2, 2, black)
    end for
end updateBullet
loop
    cls

    Input.KeyDown (keys)
    playerControls
    updateBullet

    drawline (round (player.x), round (player.y), round (player.x) + round ((cosd (player.dir) * (player.radius * 1.5))), round (player.y) + round ((sind (player.dir) * (player.radius *
        1.5))), black)
    drawfilloval (round (player.x), round (player.y), player.radius, player.radius, 12)
    View.Update
    delay (10)

    exit when keys (KEY_ESC)
end loop

Window.Close (winID)


That is ALMOST exactly what I wanted. Except I want my person to face the way of the mouse is and move with "W A S D". Side step with "A" and "D" and forward/backwards with "W" and "S".

code:
Mouse.ButtonChoose ("multibutton")

Fire with click (If z = 1 then)
Reload with rightclick (if z = 100 then)

Now I want to write the code myself so I have to do some more studying but I need help with those phew things. I like my stuff to be my own so I wont steal your code Razz


You guys really are the best! Ive never learned so much in Turing before and my game is really coming a reality : D (This movement/firing thing is my toughest obstacle)

Thanks for all the help!

Author:  Bacchus [ Sat Feb 12, 2005 6:17 pm ]
Post subject: 

Cervantes wrote:
Bacchus, you're missing a bullet.fire := false somewhere inside your loop. Wink
ya i kno it was just an example, u would set the variable to false once it either runs out of the screen or hits the target.. but i didnt want to make everything workable since it was just for him to get the idea of it.. i think i dunno i kinda forgot wat i was talking about half-way thru this message Shocked


: