Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Help With Life Counter !
Index -> Programming, Turing -> Turing Help
Goto page 1, 2  Next
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
caseyjennifer




PostPosted: 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 Sad"
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 Sad"
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
Sponsor
Sponsor
Sponsor
sponsor
RyGuy-Anime




PostPosted: 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
caseyjennifer




PostPosted: Tue Jan 24, 2012 7:23 pm   Post subject: RE:Help With Life Counter !

okay, that worked, so thanks on that Very Happy but one thing as soon as i crash it starts as soon as you crash, so what do i do there??
caseyjennifer




PostPosted: Tue Jan 24, 2012 7:25 pm   Post subject: RE:Help With Life Counter !

i did an Input.Pause and it seemed to work
RyGuy-Anime




PostPosted: 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"
Velocity




PostPosted: Wed Jan 25, 2012 12:08 am   Post subject: RE:Help With Life Counter !

i wish my culminating was this easy.
RyGuy-Anime




PostPosted: Wed Jan 25, 2012 11:27 am   Post subject: Re: Help With Life Counter !

LOL agreed, mine's over 800 lines -.-
Raknarg




PostPosted: Wed Jan 25, 2012 11:41 am   Post subject: RE:Help With Life Counter !

That may not necessarily be because of the project.
Sponsor
Sponsor
Sponsor
sponsor
caseyjennifer




PostPosted: 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
Velocity




PostPosted: 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?
caseyjennifer




PostPosted: 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 Sad
Raknarg




PostPosted: 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" Razz

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
caseyjennifer




PostPosted: Wed Jan 25, 2012 5:45 pm   Post subject: RE:Help With Life Counter !

confused :S
Dreadnought




PostPosted: Wed Jan 25, 2012 6:54 pm   Post subject: Re: Help With Life Counter !

Here's a more descriptive version of what Raknarg posted:

Turing:

% Constants and variables might be declared here


loop % Wrap the entire program in a loop to allow the user to restart

    loop % We will assume your menu requires a loop
       
        < Insert code for game menu >
             % Inside your menu you'll want the use to be able to leave the menu and start the game
             exit when < insert code to check if player wants to start game >

     end loop
     % Now they have left the menu (here you could check if they chose to quit
     %     the game entirely and use another exit when statement)

     loop % The loop for your game

          < Insert code for game >
               % Within the game there should be a statement to check if the player has lost
               exit when < player has lost >

      end loop
      %  The player has lost, bring him back to the menu
end loop


Hope this helps.
caseyjennifer




PostPosted: 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
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 2  [ 20 Posts ]
Goto page 1, 2  Next
Jump to:   


Style:  
Search: