Computer Science Canada Help With Life Counter ! |
Author: | caseyjennifer [ Tue Jan 24, 2012 7:15 pm ] |
Post subject: | Help With Life Counter ! |
Kayso, I am doing a culminating activity for computer programming and the object of the game is to move the ball around and to avoid the edges, and if you hit an edge you lose a life, but every time i run my program and hit an edge it automatically goes 3 to 2 to 1 then to you died, but i don't know what i am doing wrong and i would like help with this, so i would like my program to minus a life every time you hit an edge then let the user keep playing var x : int var y : int x := 100 y := 100 var xspeed : int var yspeed : int xspeed := 0 yspeed := 0 var life : int life := 3 var keys : array char of boolean %Controls loop Input.KeyDown (keys) if keys (KEY_UP_ARROW) and yspeed < 5 then yspeed += 1 end if if keys (KEY_DOWN_ARROW) and yspeed > -5 then yspeed -= 1 end if if keys (KEY_LEFT_ARROW) and xspeed > -5 then xspeed -= 1 end if if keys (KEY_RIGHT_ARROW) and xspeed < 5 then xspeed += 1 end if %If you crash if y >= 400 or y <= 0 then locatexy (300, 20) put "you crashed" end if if x >= 639 or x <= 0 then put "you crashed" end if y += yspeed x += xspeed %Ball Draw.FillOval (x, y, 10, 10, red) delay (10) cls %Life Counter if y >= 400 or y <= 0 then life -= 1 Text.Locate (1, 1) colour (purple) put "You Only Have ", life, " Lives Left ![]() delay (200) end if if x >= 639 or x <= 0 then life -= 1 Text.Locate (1, 1) colour (purple) put "You Only Have ", life, " Lives Left ![]() delay (200) end if %If you have 0 lifes left if life = 0 then put "You Have Died!" Input.Pause exit end if end loop |
Author: | RyGuy-Anime [ Tue Jan 24, 2012 7:20 pm ] |
Post subject: | Re: Help With Life Counter ! |
Try resetting your location when you crash so the life doesn't keep going down ex: %Life Counter if y >= 400 or y <= 0 then life -= 1 Text.Locate (1, 1) colour (purple) put "You Only Have ", life, " Lives Left " y:= 100 x:= 100 delay (200) end if |
Author: | caseyjennifer [ Tue Jan 24, 2012 7:23 pm ] |
Post subject: | RE:Help With Life Counter ! |
okay, that worked, so thanks on that ![]() |
Author: | caseyjennifer [ Tue Jan 24, 2012 7:25 pm ] |
Post subject: | RE:Help With Life Counter ! |
i did an Input.Pause and it seemed to work |
Author: | RyGuy-Anime [ Tue Jan 24, 2012 7:29 pm ] |
Post subject: | Re: Help With Life Counter ! |
That or a delay (1 or 2 seconds), also u may wanna tell the user something like "oh no you crashed! you have ", life,"s left.. press an arrowkey to continue" |
Author: | Velocity [ Wed Jan 25, 2012 12:08 am ] |
Post subject: | RE:Help With Life Counter ! |
i wish my culminating was this easy. |
Author: | RyGuy-Anime [ Wed Jan 25, 2012 11:27 am ] |
Post subject: | Re: Help With Life Counter ! |
LOL agreed, mine's over 800 lines -.- |
Author: | Raknarg [ Wed Jan 25, 2012 11:41 am ] |
Post subject: | RE:Help With Life Counter ! |
That may not necessarily be because of the project. |
Author: | caseyjennifer [ Wed Jan 25, 2012 4:27 pm ] |
Post subject: | RE:Help With Life Counter ! |
well we just have to make a game or a game accessory.. mine is short because i started it monday, and it is due on friday because of exams |
Author: | Velocity [ Wed Jan 25, 2012 4:33 pm ] |
Post subject: | RE:Help With Life Counter ! |
ryguy, i didnt mean in lines, i was referring to the language. casey, do you need anymore help with your project? |
Author: | caseyjennifer [ Wed Jan 25, 2012 5:20 pm ] |
Post subject: | RE:Help With Life Counter ! |
yeah kinda... i don't know how to make a start menu, and i don't know a good title ![]() |
Author: | Raknarg [ Wed Jan 25, 2012 5:29 pm ] |
Post subject: | RE:Help With Life Counter ! |
Title matters little. You can make it generic. I had a prokect that was a side scrolling game like Galaga, and I just called it "Shooting Game" ![]() Start menu is easy. You just haave 2 loops like this loop Loop startmenu() if they exit, then exit end loop loop game() if they win or lose, then exit end loop end loop |
Author: | caseyjennifer [ Wed Jan 25, 2012 5:45 pm ] |
Post subject: | RE:Help With Life Counter ! |
confused :S |
Author: | Dreadnought [ Wed Jan 25, 2012 6:54 pm ] | ||
Post subject: | Re: Help With Life Counter ! | ||
Here's a more descriptive version of what Raknarg posted:
Hope this helps. |
Author: | caseyjennifer [ Wed Jan 25, 2012 7:29 pm ] |
Post subject: | RE:Help With Life Counter ! |
omg, for my life counter, i took RyGuy's idea of press any arrow key to continue, but when i typed it in and ran my program, when i was at 0 lifes it said you have 0 lives left press any arrow key to continue how do i change that so it doesnt say that when i get 0 lives? %Life Counter if y >= 400 or y <= 0 then life -= 1 Text.Locate (1, 1) colour (purple) put "You Only Have ", life, " Lives Left Press Any Arrow Key To Continue " y := 100 x := 100 Input.Pause end if %If you have 0 lifes left if life = 0 then put "You Have Died!" Input.Pause exit end if end loop |
Author: | Raknarg [ Wed Jan 25, 2012 9:22 pm ] |
Post subject: | RE:Help With Life Counter ! |
It's most likely because if the order. When you lose a life, it goes through the massage first. After that, it exits the loop. Find a way so that when you hit zero lifes it exits instead of displaying a message. @Dreadnaught thanks, I'm too tired for this ![]() |
Author: | Velocity [ Thu Jan 26, 2012 12:56 am ] |
Post subject: | RE:Help With Life Counter ! |
why do you use input.pause? if life less than one then cls put you lose. |
Author: | Raknarg [ Thu Jan 26, 2012 2:06 pm ] |
Post subject: | RE:Help With Life Counter ! |
The idea is that every time you lose a life, the game pauses, then you click any button to continue. |
Author: | Velocity [ Thu Jan 26, 2012 11:06 pm ] |
Post subject: | RE:Help With Life Counter ! |
you cant since ur if statement already does it, or say if life equals 0 then cls put ... |
Author: | Velocity [ Thu Jan 26, 2012 11:07 pm ] |
Post subject: | RE:Help With Life Counter ! |
so its the same as getch delay? Ooohhh okay i get it, thats neat, |