Computer Science Canada

Frogger Game

Author:  Jessica359 [ Wed Apr 30, 2008 12:37 pm ]
Post subject:  Frogger Game

Allo...again Laughing
I am making a frogger game as an end of year project. This is what I have so far and I need advice.

1. I don't know how to get the program to exit out when the green circle hits one of the boxes.
2. Does anyone have any suggestions on how to improve it or what would be cool to put in it or why are you doing this game its too easy lol i dunno anything Smile

thanks

Smile

Author:  metachief [ Wed Apr 30, 2008 12:58 pm ]
Post subject:  RE:Frogger Game

weird game...
first of all do you know how to use whatdotcolor function?
or do you know how to find the distance between two objects?
you could use the formula :distance = sqrt ((x2-x1)**2+(y2-y1)**2)
to find the distance between your circle and the boxes, but that would take too long assuming yu don't know arrays yet. Therefore I suggest using "whatdotcolor" eventhough it is inefficient way of doing it.
If you don't know how to use whatdotcolor then search for a tutorial, I think someone made one for it. Also I suggest learning about arrays.
Oh and make the boxes go the opposite way when they reach the end of the screen, or make new ones appear.

Author:  Jessica359 [ Wed Apr 30, 2008 1:03 pm ]
Post subject:  RE:Frogger Game

hey,

it might be a wierd game but its awesome Smile

I researched whatdotcolor i put it into my program but it didn't do anything. Also we did learn about arrays and 2 dimensional arrays.
i'm just not sure were to start.

Author:  metachief [ Wed Apr 30, 2008 1:59 pm ]
Post subject:  RE:Frogger Game

an array is very simple: instead of one variable representing one thing, an array variable represents as many as you put.
For example:
var number : array 1..10 of int
what that does is the variable number can now store 10 intergers in it and you select each one by having a subscript of number. For eaxample number (2) will give you the 2nd number.
You can specify the numbers by doing this:
var number : array 1..10 of int:=init (2,21,43,12,12,34,23,54,56,76)
So now if you say number (2) it will give you 21 scince that is the second number in your array that you specified.

Author:  Jessica359 [ Thu May 01, 2008 7:44 am ]
Post subject:  RE:Frogger Game

ok ya we learned that but how is that suppose to help me get its to exit when it hits the cars?

Smile

Author:  S_Grimm [ Thu May 01, 2008 10:39 am ]
Post subject:  Re: Frogger Game

My best advice is to use something like this: (sorry, i can't really give specifics, had a hard time figuring out code)

code:

if (location of box1 = location of frog) or (location of box2 = location of frog) or ...........................  then
put "You Got Run Over"
end game
else
REST OF YOUR CODE
end if


the location is the x,y co-ordinates

Author:  Jessica359 [ Thu May 01, 2008 12:35 pm ]
Post subject:  RE:Frogger Game

Awesome that makes much more sense!
Thanks for your help guys Smile

Author:  Jessica359 [ Thu May 01, 2008 12:53 pm ]
Post subject:  Re: Frogger Game

Alright so another thing came up.
I took you idea of putting and if statement in.

code:

if x = boxx and y = boxy and x=boxy and y=boxx then
cls
put"GAME OVER"
end if


But its not working?
My teacher told me something about keeping track of the x and y coordinates of the frog and boxes and something else about global declaration. Its just confusing Confused

Any other sujestions on how to tell it to quit when it hits a box?

thnxs Smile

Author:  S_Grimm [ Thu May 01, 2008 12:57 pm ]
Post subject:  RE:Frogger Game

ok, what is your variable for Frog?

Author:  Jessica359 [ Thu May 01, 2008 1:32 pm ]
Post subject:  RE:Frogger Game

Its ok i got it to work by putting this in (the frog is x,y)

code:

     if x >= boxx and x <= boxx +80 and y >= boxy and y <= boxy +80 then
        cls
        put "GAME OVER"


So now when it his teh white box it clears teh background and says game over but as soon as the box is pass the frog the game keeps going.
Smile

Author:  Sean [ Thu May 01, 2008 2:06 pm ]
Post subject:  RE:Frogger Game

Change the cls to an exit

Turing:

if x >= boxx and x <= boxx + 80 and y >= boxy and y <= boxy + 80 then
     exit
end if

Author:  Jessica359 [ Fri May 02, 2008 8:54 am ]
Post subject:  RE:Frogger Game

ya i thought of that except its not in a loop and when i put a loop in it messed up and doesn't even work.

Author:  Sean [ Fri May 02, 2008 11:22 am ]
Post subject:  RE:Frogger Game

Your game should be in a loop, so you have constant movement of the picture.

Author:  petree08 [ Fri May 02, 2008 11:29 am ]
Post subject:  RE:Frogger Game

add this to keep your cars going

(mind this is genaric and not specific to your code)

if (CarX +CarLength ) < 1 then
CarX := maxx
elsif ( CarX -CarLength )> maxx then
CarX :=1
end if

Author:  Asherel [ Fri May 02, 2008 2:22 pm ]
Post subject:  Re: Frogger Game

As Sean mentioned, your game should always be in a loop to allow continuous movement of your character, which happens to be Frogger.

There are ways to do it without loops, however since you're the one moving Frogger, you would have Input.KeyDown in your code.

Input.KeyDown allows you to manoeuver around the screen, if it is in a loop you can do this continuously until you meet a certain condition, or hit boundaries. Without the loop, one click and it stops completely.

When I have access to a computer that has my example program, I'll post it as an example. It has collision of dots, and then exits when the AI equals the Character.

So, to answer your question on how to exit it. Have a main program loop, and then when the condition of the two dots colliding is met, exit the program with the exit function.

Author:  Jessica359 [ Mon May 05, 2008 9:16 am ]
Post subject:  RE:Frogger Game

Ok so i got the cars to keep moving except when i put my overall program in a loop the game doesn't work or doesn't even start.

Author:  S_Grimm [ Mon May 05, 2008 10:38 am ]
Post subject:  RE:Frogger Game

Can you post the updated version with the modifications you made, so we can take another look at it?

Author:  Jessica359 [ Mon May 05, 2008 11:18 am ]
Post subject:  Re: Frogger Game

Here is what I have so far Cool

Author:  S_Grimm [ Mon May 05, 2008 11:57 am ]
Post subject:  Re: Frogger Game

ok, I took a look and determined this :
1) Exit does not work.
2) Boolean statements do.
I'm posting a modified version of the game that has my boolean statements in it. Basically what i did is this:
when your code says
code:

if x=boxx (blah, blah) then
cls
put "Game Over"
gameover :=  true
end if

then at the bottom of your code,
code:

loop

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and y < 430 then
        y := y + 5
    end if
    if chars (KEY_DOWN_ARROW) and y > 10 then
        y := y - 5
    end if
    if chars (KEY_RIGHT_ARROW) and x < 700 then
        x := x + 5
    end if
    if chars (KEY_LEFT_ARROW) and x > 10 then
        x := x - 5
    end if
    Pic.Draw (back, 0, 0, picCopy)
    frog
    View.Update
    exit when gameover = true
end loop


It works, and it's increadably clean.


Ps. I didn't try to get the cars to loop yet.

Author:  Jessica359 [ Tue May 06, 2008 8:05 am ]
Post subject:  Re: Frogger Game

Hello,
AWESOME! It works really well, also how so u set boundaries? Like when the frog hits the blue water the game will freeze and tell it "You have Won!" ?

Author:  S_Grimm [ Tue May 06, 2008 10:24 am ]
Post subject:  RE:Frogger Game

determine the y position of the water and put in
CODE:
var waterhit : boolean := false
if y => (y co-ordinite of water) then
waterhit := true


then in the loop type
CODE:
exit when waterhit = true

outside of the loop
CODE:
if watertrue = true then
cls
put "You Win!"
end if

Author:  Jessica359 [ Thu May 08, 2008 10:02 am ]
Post subject:  Re: Frogger Game

code:

if y => 100 then


It tells me that the 100 has to be of a boolean type? Confused

Author:  S_Grimm [ Fri May 09, 2008 11:00 am ]
Post subject:  RE:Frogger Game

to correct my mistake it has to be


y >= 100 then

its the greater than sign then the equals sign. My bad. srry

Author:  Jessica359 [ Mon May 12, 2008 8:59 am ]
Post subject:  RE:Frogger Game

its ok Smile

so i put the equation in and all and the game is working except it doesn't do anything when
y>=100
is the 100 wrong or the y isn't the right variable?

Author:  Jessica359 [ Mon May 12, 2008 9:21 am ]
Post subject:  RE:Frogger Game

Scratch that last comment i got it to work, it was my stupid mistake Smile lol
thnxs

Author:  S_Grimm [ Mon May 12, 2008 11:20 am ]
Post subject:  RE:Frogger Game

no problem
great work on the program by the way.

Author:  Jessica359 [ Mon May 12, 2008 11:25 am ]
Post subject:  RE:Frogger Game

lol thanks i'll be needing much more help though! lol Smile
so far no bugs lol Smile

Author:  Jessica359 [ Tue May 13, 2008 7:41 am ]
Post subject:  Re: Frogger Game

Well here another problem Laughing
This is mythird level and I have the cars changing lanes except i want it that when the car hits the water or the grass it will just bonce off. What can I use to do that?

code:


View.Set ("graphics, offscreenonly")
setscreen ("graphics:720;450")

var font1 : int
font1 := Font.New ("Castellar:50")

var x, y : int := 20
var chars : array char of boolean
var anglex : int := 135
var angley : int := 225
var frog2 : boolean := true
var score : int := 3
var back : int := Pic.FileNew ("background.bmp")
var waterhit : boolean := false


var boxx : int := 600
var boxy : int := 40
var boxx2 : int := 600
var boxy2 : int := 125
var boxx3 : int := 0
var boxy3 : int := 210
var boxx4 : int := 0
var boxy4 : int := 285
var boxx5 : int := 750
var boxy5 : int := 40
var boxx6 : int := 600
var boxy6 : int := 125
var boxx7 : int := 0
var boxy7 : int := 285
var boxx8 : int := 0
var boxy8 : int := 210

var gameover : boolean := false


procedure last
    drawfill (50, 50, 7, 7)
end last


procedure frog
    if frog2 then
        %exit when anglex = 135 and angley = 225
        Draw.FillOval (x, y, 20, 20, green)
        anglex := anglex - 1
        angley := angley + 1
        delay (20)
        if anglex = 135 and angley = 225 then
            frog2 := true
        end if
    end if


    % Boxes
    drawfillbox (boxx, boxy, boxx + 80, boxy + 60, 0)
    delay (12)
    boxx := boxx - 15


    drawfillbox (boxx2, boxy2, boxx2 + 80, boxy2 + 60, 59)
    delay (12)
    boxx2 := boxx2 - 4

    drawfillbox (boxx3, boxy3, boxx3 + 80, boxy3 + 60, 37)
    delay (12)
    boxx3 := boxx3 + 10

    drawfillbox (boxx4, boxy4, boxx4 + 80, boxy4 + 60, 45)
    delay (12)
    boxx4 := boxx4 + 9

    drawfillbox (boxx5, boxy5, boxx5 + 80, boxy5 + 60, 40)
    delay (12)
    boxx5 := boxx5 - 7

    drawfillbox (boxx6, boxy6, boxx6 + 80, boxy6 + 60, 7)
    delay (12)
    boxx6 := boxx6 - 10
    drawfillbox (boxx7, boxy7, boxx7 + 80, boxy7 + 60, 52)
    delay (12)
    boxx7 := boxx7 + 5

    drawfillbox (boxx8, boxy8, boxx8 + 80, boxy8 + 60, 101)
    delay (12)
    boxx8 := boxx8 + 30
   
    boxy8:= boxy8 +2


    % Boxes Moving
    if x <= boxx + 70 and x + 50 >= boxx then
        if y <= boxy + 70 and y + 50 >= boxy then
            score := score - 1
        end if
    end if

    if x <= boxx2 + 70 and x + 50 >= boxx2 then
        if y <= boxy2 + 70 and y + 50 >= boxy2 then
            score := score - 1
        end if
    end if

    if x <= boxx3 + 70 and x + 50 >= boxx3 then
        if y <= boxy3 + 70 and y + 50 >= boxy3 then
            score := score - 1
        end if
    end if

    if x <= boxx4 + 70 and x + 50 >= boxx4 then
        if y <= boxy4 + 70 and y + 50 >= boxy4 then
            score := score - 1
        end if
    end if

    if x <= boxx5 + 70 and x + 50 >= boxx5 then
        if y <= boxy5 + 70 and y + 50 >= boxy5 then
            score := score - 1
        end if
    end if

    if x <= boxx6 + 70 and x + 50 >= boxx6 then
        if y <= boxy6 + 70 and y + 50 >= boxy6 then
            score := score - 1
        end if
    end if

    if x <= boxx7 + 70 and x + 50 >= boxx7 then
        if y <= boxy7 + 70 and y + 50 >= boxy7 then
            score := score - 1
        end if
    end if

    if x <= boxx8 + 70 and x + 50 >= boxx8 then
        if y <= boxy8 + 70 and y + 50 >= boxy8 then
            score := score - 1
        end if
    end if



    % Boxes keep coming on the screen.
    if (boxx + boxy) < 1 then
        boxx := maxx
    elsif (boxx - boxy) > maxx then
        boxx := 1
    end if

    if (boxx2 + boxy2) < 1 then
        boxx2 := maxx
    elsif (boxx2 - boxy2) > maxx then
        boxx2 := 1
    end if

    if (boxx3 + boxy3) < 1 then
        boxx3 := maxx
    elsif (boxx3 - boxy3) > maxx then
        boxx3 := 1
    end if

    if (boxx4 + boxy4) < 1 then
        boxx4 := maxx
    elsif (boxx4 - boxy4) > maxx then
        boxx4 := 1
    end if

    if (boxx5 + boxy5) < 1 then
        boxx5 := maxx
    elsif (boxx5 - boxy5) > maxx then
        boxx5 := 1
    end if

    if (boxx6 + boxy6) < 1 then
        boxx6 := maxx
    elsif (boxx6 - boxy6) > maxx then
        boxx6 := 1
    end if

    if (boxx7 + boxy7) < 1 then
        boxx7 := maxx
    elsif (boxx7 - boxy7) > maxx then
        boxx7 := 1
    end if

    if (boxx8 + boxy8) < 1 then
        boxx8 := maxx
    elsif (boxx8 - boxy8) > maxx then
        boxx8 := 1
    end if

    %When the frog hits the boxes the game exits.
    if y >= 340 then
        waterhit := true
    end if


    if x >= boxx and x <= boxx + 80 and y >= boxy and y <= boxy + 80 then
        cls
        last
        Font.Draw ("GAME OVER", 150, 225, font1, 0)

        gameover := true

    elsif x >= boxx2 and x <= boxx2 + 80 and y >= boxy2 and y <= boxy2 + 80 then
        cls
        last
        Font.Draw ("GAME OVER", 150, 225, font1, 0)

        gameover := true
    elsif x >= boxx3 and x <= boxx3 + 80 and y >= boxy3 and y <= boxy3 + 80 then
        cls
        last
        Font.Draw ("GAME OVER", 150, 225, font1, 0)

        gameover := true
    elsif x >= boxx4 and x <= boxx4 + 80 and y >= boxy4 and y <= boxy4 + 80 then
        cls
        last
        Font.Draw ("GAME OVER", 150, 255, font1, 0)

        gameover := true
    elsif x >= boxx5 and x <= boxx5 + 80 and y >= boxy5 and y <= boxy5 + 80 then
        cls
        last
        Font.Draw ("GAME OVER", 150, 225, font1, 0)

        gameover := true
    elsif x >= boxx6 and x <= boxx6 + 80 and y >= boxy6 and y <= boxy6 + 80 then
        cls
        last
        Font.Draw ("GAME OVER", 150, 225, font1, 0)

        gameover := true
    elsif x >= boxx7 and x <= boxx7 + 80 and y >= boxy7 and y <= boxy7 + 80 then
        cls
        last
        Font.Draw ("GAME OVER", 150, 225, font1, 0)

        gameover := true
    elsif x >= boxx8 and x <= boxx8 + 80 and y >= boxy8 and y <= boxy8 + 80 then
        cls
        last
        Font.Draw ("GAME OVER", 150, 225, font1, 0)

        gameover := true

    end if

    if waterhit = true then
        cls
        put "You Win!"
    end if


end frog


% Makes sure frog moves with arrow keys.
loop

    Input.KeyDown (chars)
    if chars (KEY_UP_ARROW) and y < 430 then
        y := y + 5
    end if
    if chars (KEY_DOWN_ARROW) and y > 10 then
        y := y - 5
    end if
    if chars (KEY_RIGHT_ARROW) and x < 700 then
        x := x + 5
    end if
    if chars (KEY_LEFT_ARROW) and x > 10 then
        x := x - 5
    end if
    Pic.Draw (back, 0, 0, picCopy)
    frog
    View.Update
    exit when waterhit = true
    exit when gameover = true




end loop

Author:  S_Grimm [ Tue May 13, 2008 10:50 am ]
Post subject:  RE:Frogger Game

again, ill use sudocode for this. take the algorithim that moves the car across the lane and add this:

if car = water then
reverse direction of car
end if
if car = grass then
reverse direction of car
end if


use the y co-ordinates for the grass and water and for the reversal or car just use opposites (ie if your movement is y +2 then turn it to y-2)

Author:  Jessica359 [ Tue May 13, 2008 11:16 am ]
Post subject:  Re: Frogger Game

Ah that makes much more sense then wat i was told to do. Smile
sry if i'm bugging u with questions lol Smile

Author:  S_Grimm [ Tue May 13, 2008 11:26 am ]
Post subject:  RE:Frogger Game

it might not work, i've yet to try it.

Author:  Jessica359 [ Wed May 14, 2008 4:16 pm ]
Post subject:  Re: Frogger Game

This time it has to do with boundaries. I'm getting my gars to change lanes for my third level so I got it that when it hits the water it bounces off except I can't get it to do the same when it comes to hit that grass, i have it bouncing iff but it just keeps bouncing back its not going back up. Here the specific lines.
code:

     boxy8 := boxy8 + 2
   
            if boxy8 >= 285 then
        carhitw := true
end if

    if carhitw = true and boxy8 >= 50 then
     boxy8 := boxy8 - 5
     elsif carhitw = true and boxy8 <= 50 then
     boxy8 := boxy8 + 2
     end if
      boxy8 := boxy8 + 2


Heres the entire program if you need it.

Author:  S_Grimm [ Fri May 16, 2008 10:22 am ]
Post subject:  Re: Frogger Game

You needed to use a if carhitw = false statement to make it move up. ill post it here for you

Author:  Jessica359 [ Fri May 16, 2008 7:34 pm ]
Post subject:  RE:Frogger Game

ok cool, i forgot to write that i had alreadu figured it out but i got the excat same thing lol Smile thxs though lol ;p
Now i have one more question and this should be one of my last ones lol how would i interconnect all my lelves. cuz when i put them in procedure they mess up?

thnxs Smile

Author:  S_Grimm [ Sat May 17, 2008 11:36 am ]
Post subject:  RE:Frogger Game

can u post all the lvls in a zip folder for me? i need to have the differences to work with.

Author:  Sean [ Sat May 17, 2008 11:51 am ]
Post subject:  Re: Frogger Game

You can make a variable for levels, and then if a person beats a level then it increases and goes to next.

Turing:

var level : real := 0

if level = 0 then
%Map
     if character_x = finish_x and character_y = finish_y then
         level +=1
     end if
end if

if level = 1 then
%Same Thing as above
end if


This is how we used to do it in the days of Mario. Mackie and I devised this ages ago, however we never moved onto a further one. Secondly, I bet there is a more efective way, however this is one way to do it.

Author:  riveryu [ Sat May 17, 2008 12:32 pm ]
Post subject:  RE:Frogger Game

also, just a suggestion. If your levels only involve very simple changes then you can write a procedure to create levels for you. If dont know already, try to learn to use arrays. Tutorial here http://compsci.ca/v3/viewtopic.php?t=14333
A very simple example here...
Turing:
proc (var boxspeed array 1..5 of real, var boxLength, boxheight : array 1 .. 5 of int)
for i : 1.. 5
boxvx(i) := boxspeed(i) %you can even add some random factors in your levels
boxH(i):=boxheight(i)
boxL(i):=boxLength(i)
end for
end proc

Correct me if im wrong somewhere...

Author:  Jessica359 [ Sun May 18, 2008 7:20 pm ]
Post subject:  Re: Frogger Game

Alright so heres the 3 levels i have.

Author:  Jessica359 [ Wed May 21, 2008 4:58 pm ]
Post subject:  RE:Frogger Game

is this any help? :s

Author:  Jessica359 [ Wed May 21, 2008 5:16 pm ]
Post subject:  Re: Frogger Game

ok so i tried this method here, exept it gives me an error of "'procedure' may only be declared at the program, module, or monitor level."
wat can i do?

Author:  S_Grimm [ Thu May 22, 2008 10:43 am ]
Post subject:  RE:Frogger Game

i'm trying, but it eludes me. It keeps bypassing the second and third levels and finishing the program

Author:  Jessica359 [ Thu May 22, 2008 3:49 pm ]
Post subject:  RE:Frogger Game

ah ok thxs for trying, does any1 else know by any chance?

Author:  riveryu [ Fri May 23, 2008 10:56 pm ]
Post subject:  RE:Frogger Game

I've looked at your program. Heres a few comments according to ur latest uploaded version, "FROGGER put together.t"
- do not loop decalartions of anything such as vars, procedures etc.. i killed that loop u had and it worked
-also, procedure can abbreviated as "proc"
-you can set everything for View.Set or setscreen in one call.
ex. View.Set ("graphics:700;600,offscreenonly")

Author:  Jessica359 [ Thu May 29, 2008 9:22 am ]
Post subject:  Re: Frogger Game

Ok so I got it to change levels with the "include" function. So when you click on the intro screen it should start the program except it goes to "lvl1" and gives me an error on the first 2 procedures. Is there something i'm doing wrong?

thnxs Smile

Author:  S_Grimm [ Fri May 30, 2008 10:36 am ]
Post subject:  RE:Frogger Game

your procedures are all named the same (frog). "frog" has already been declared by the first level. call the other procedures something else.

Author:  Jessica359 [ Fri May 30, 2008 1:35 pm ]
Post subject:  RE:Frogger Game

k i fixed it its all good now Smile


: