Making Food
Author |
Message |
Mr. T
|
Posted: Sun Mar 20, 2005 9:32 pm Post subject: Making Food |
|
|
Can someone help me...im having issues with var makeFood :boolean
my goal is to always make food except when the exit point is open
(ive tried many variations but for some reason it screws up my scoring sometimes)
Please Help!!!
------------------------------
code: |
%variable declaration
View.Set ("graphics:500;400,title:Uncle Worm Score: 0")
var food1 : int
var food2 : int
var foodSize : int
var makeFood:boolean:=true
var box1 : int := 0
var box4 : int := 0
var col : int := 31
var countdown : int := 6
var ballx1 : int := 200
var bally1 : int := 150
var ballsize : int := 5
var move, move2, move3, move4 := false
var key : array char of boolean
var ring : int := 0
var answer : string
move3 := true %starting direction of snake
var newMaxX : int := 500 %innitial screen dimensions (x co-ords)
var newMaxY : int := 400 %innitial screen dimensions (y co-ords)
var levelUpX : int := 50 %decrease in screen dimensions (x co-ords) upon completion of level
var levelUpY :int :=40 %decrease in screen dimensions (y co-ords) upon completion of level
var scoreLevel : int := 50
var foodBoolean :boolean
var score : int :=0 %score
%gives time for user to get ready
loop
locate (12, 25)
put "Starting in...", countdown - 1
delay (300)
countdown := countdown - 1
cls
exit when countdown = 0
end loop
%creates food in random locations
procedure food
if makeFood then
randint (food1, 1, newMaxX-10) %random food location (but not in the walls)
randint (food2, 1, newMaxY-10) %random food location (but not in the walls)
randint (foodSize, 2, 10) %random food size
drawfilloval (food1, food2, foodSize, foodSize, 2)
end if
end food
%point of contact upon death
procedure ringEnd
loop
drawoval (ballx1, bally1, ballsize + ring, ballsize + ring, ring)
ring += 2
delay (10)
exit when ring = 100
end loop
end ringEnd
%draws food
food
%snake movement
loop
drawbox (box1, newMaxY-1, newMaxX-1, box4, 7)
drawfilloval (ballx1, bally1, ballsize, ballsize, col)
if move then
bally1 += 1
elsif move2 then
bally1 -= 1
elsif move3 then
ballx1 += 1
elsif move4 then
ballx1 -= 1
end if
Input.KeyDown (key)
if key (KEY_UP_ARROW) and move2 = false then %Two Conditions: 1. up arrow is pressed 2. move2 = false
move2 := false
move3 := false
move4 := false
move := true
elsif key (KEY_DOWN_ARROW) and move = false then %Two Conditions: 1. down arrow is pressed 2. move = false
move := false
move3 := false
move4 := false
move2 := true
elsif key (KEY_RIGHT_ARROW) and move4 = false then %Two Conditions: 1. right arrow is pressed 2. move4 = false
move := false
move2 := false
move4 := false
move3 := true
elsif key (KEY_LEFT_ARROW) and move3 = false then %Two Conditions: 1. left arrow is pressed 2. move3 = false
move := false
move2 := false
move3 := false
move4 := true
end if
drawfilloval (ballx1, bally1, ballsize, ballsize, 12) %deletes the tail
delay (10)
%wall collision detection
if ballx1 = 4 or ballx1 = maxx - 4 or bally1 = 4 or bally1 = maxy - 4 then
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score) + " You Lose!")
ringEnd
exit
end if
%food collision detection
if whatdotcolour (food1 + foodSize, food2 + foodSize) = 12 or whatdotcolour (food1 - foodSize, food2 - foodSize) = 12
then
score += 10 %when food collision detected points are added to score
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score))
drawfilloval (food1, food2, foodSize, foodSize, white) %so that no chunk of food is left behind
makeFood:=true
food
end if
%NEXT LEVEL
if score >= scoreLevel
then drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 4)
makeFood:=false
end if
if whatdotcolour (ballx1+ballsize,bally1+ballsize)=4
then cls
var bonus:int:=60000 div 1000 %1 min to be able to get bonus
var timeBonus:int :=bonus-Time.Elapsed div 1000
score:=score+timeBonus
put "Your score is: ", score
put "Your time bonus is: ", timeBonus
put "Your overall score is: ", score
put "[press any key to continue to next round]"
Input.Pause
newMaxX:=newMaxX-levelUpX
newMaxY:=newMaxY-levelUpY
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score))
ballx1:=newMaxX div 2 %new x co-ords for the start of a new level
bally1:=newMaxY div 2 %new y co-ords for the start of a new level
makeFood:=true
food
scoreLevel:=score+50
end if
end loop
View.Update
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Delos
|
Posted: Sun Mar 20, 2005 10:00 pm Post subject: (No subject) |
|
|
code: |
%food collision detection
if whatdotcolour (food1 + foodSize, food2 + foodSize) = 12 or whatdotcolour (food1 - foodSize, food2 - foodSize) = 12
then
score += 10 %when food collision detected points are added to score
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score))
drawfilloval (food1, food2, foodSize, foodSize, white) %so that no chunk of food is left behind
%makeFood := true
food
end if
|
Note the new commented line. I.e., the line that was removed.
Try it now...you get one extra food after the last one is taken...I'm sure you can figure out how to get rid of that. |
|
|
|
|
|
Bacchus
|
Posted: Sun Mar 20, 2005 10:01 pm Post subject: (No subject) |
|
|
code: | %food collision detection
if whatdotcolour (food1 + foodSize, food2 + foodSize) = 12 or whatdotcolour (food1 - foodSize, food2 - foodSize) = 12
then
score += 10 %when food collision detected points are added to score
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score))
drawfilloval (food1, food2, foodSize, foodSize, white) %so that no chunk of food is left behind
makeFood:=true
food
end if | you dont need to set the boolean to true there and accually you should have a check to make sure its not off cause your making the food b4 ur cheking to see if the score is ready to goto next lvl
code: | %food collision detection
if whatdotcolour (food1 + foodSize, food2 + foodSize) = 12 or whatdotcolour (food1 - foodSize, food2 - foodSize) = 12
then
score += 10 %when food collision detected points are added to score
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score))
drawfilloval (food1, food2, foodSize, foodSize, white) %so that no chunk of food is left behind
if score<scoreLevel then %like this after they get improved score
food %if its still to low to advance then makes
end if %more food
end if |
|
|
|
|
|
|
Mr. T
|
Posted: Sun Mar 20, 2005 10:08 pm Post subject: (No subject) |
|
|
dear god it works...i never thought this day would come |
|
|
|
|
|
Bacchus
|
Posted: Sun Mar 20, 2005 10:09 pm Post subject: (No subject) |
|
|
i did the exact same thing in the other post lol |
|
|
|
|
|
Mr. T
|
Posted: Sun Mar 20, 2005 10:11 pm Post subject: (No subject) |
|
|
wait...as mentioned previously...now that the makeFood is ok, the score is screwed up....it should increment by 10s and for some reaosn it suddenyl jumps up by 100 :S:S
check the new code and see...
code: |
%variable declaration
View.Set ("graphics:500;400,title:Uncle Worm Score: 0")
var food1 : int
var food2 : int
var foodSize : int
var makeFood:boolean:=true
var box1 : int := 0
var box4 : int := 0
var col : int := 31
var countdown : int := 6
var ballx1 : int := 200
var bally1 : int := 150
var ballsize : int := 5
var move, move2, move3, move4 := false
var key : array char of boolean
var ring : int := 0
var answer : string
move3 := true %starting direction of snake
var newMaxX : int := 500 %innitial screen dimensions (x co-ords)
var newMaxY : int := 400 %innitial screen dimensions (y co-ords)
var levelUpX : int := 50 %decrease in screen dimensions (x co-ords) upon completion of level
var levelUpY :int :=40 %decrease in screen dimensions (y co-ords) upon completion of level
var scoreLevel : int := 50
var foodBoolean :boolean
var score : int :=0 %score
%gives time for user to get ready
loop
locate (12, 25)
put "Starting in...", countdown - 1
delay (300)
countdown := countdown - 1
cls
exit when countdown = 0
end loop
%creates food in random locations
procedure food
if makeFood then
randint (food1, 1, newMaxX-10) %random food location (but not in the walls)
randint (food2, 1, newMaxY-10) %random food location (but not in the walls)
randint (foodSize, 2, 10) %random food size
drawfilloval (food1, food2, foodSize, foodSize, 2)
end if
end food
%point of contact upon death
procedure ringEnd
loop
drawoval (ballx1, bally1, ballsize + ring, ballsize + ring, ring)
ring += 2
delay (10)
exit when ring = 100
end loop
end ringEnd
%draws food
food
%snake movement
loop
drawbox (box1, newMaxY-1, newMaxX-1, box4, 7)
drawfilloval (ballx1, bally1, ballsize, ballsize, col)
if move then
bally1 += 1
elsif move2 then
bally1 -= 1
elsif move3 then
ballx1 += 1
elsif move4 then
ballx1 -= 1
end if
Input.KeyDown (key)
if key (KEY_UP_ARROW) and move2 = false then %Two Conditions: 1. up arrow is pressed 2. move2 = false
move2 := false
move3 := false
move4 := false
move := true
elsif key (KEY_DOWN_ARROW) and move = false then %Two Conditions: 1. down arrow is pressed 2. move = false
move := false
move3 := false
move4 := false
move2 := true
elsif key (KEY_RIGHT_ARROW) and move4 = false then %Two Conditions: 1. right arrow is pressed 2. move4 = false
move := false
move2 := false
move4 := false
move3 := true
elsif key (KEY_LEFT_ARROW) and move3 = false then %Two Conditions: 1. left arrow is pressed 2. move3 = false
move := false
move2 := false
move3 := false
move4 := true
end if
drawfilloval (ballx1, bally1, ballsize, ballsize, 12) %deletes the tail
delay (10)
%wall collision detection
if ballx1 = 4 or ballx1 = maxx - 4 or bally1 = 4 or bally1 = maxy - 4 then
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score) + " You Lose!")
ringEnd
exit
end if
%food collision detection
if whatdotcolour (food1 + foodSize, food2 + foodSize) = 12 or whatdotcolour (food1 - foodSize, food2 - foodSize) = 12
then
score += 10 %when food collision detected points are added to score
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score))
drawfilloval (food1, food2, foodSize, foodSize, white) %so that no chunk of food is left behind
if score<scoreLevel then
food
end if
end if
%NEXT LEVEL
if score >= scoreLevel
then drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 4)
makeFood:=false
end if
if whatdotcolour (ballx1+ballsize,bally1+ballsize)=4
then cls
%scoring system
var bonus:int:=60000 div 1000 %1 min to be able to get bonus
var timeBonus:int :=bonus-Time.Elapsed div 1000
score:=score+timeBonus
put "Your score is: ", score
put "Your time bonus is: ", timeBonus
put "Your overall score is: ", score
put "[press any key to continue to next round]"
Input.Pause
%variable reset
newMaxX:=newMaxX-levelUpX
newMaxY:=newMaxY-levelUpY
View.Set ("graphics:" + intstr (newMaxX) + ";" + intstr (newMaxY) + ",title:Uncle Worm Score: " + intstr (score))
ballx1:=newMaxX div 2 %new x co-ords for the start of a new level
bally1:=newMaxY div 2 %new y co-ords for the start of a new level
makeFood:=true
food
scoreLevel:=score+50
end if
end loop
View.Update
|
|
|
|
|
|
|
|
|