whatdotcolour
Author |
Message |
Mr. T
|
Posted: Sun Mar 20, 2005 1:50 am Post subject: whatdotcolour |
|
|
for my snake game, why doesnt the what dot colour work?
code: |
%NEXT LEVEL
if score = scoreLevel
then
drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 4)
scoreLevel += 10
exit when whatdotcolour (ballx1+ballsize,bally1+ballsize)=4
end if
|
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Bacchus
|
Posted: Sun Mar 20, 2005 2:18 am Post subject: (No subject) |
|
|
where the loop or for loop that its all in? you have an exit but no loop |
|
|
|
|
|
Mr. T
|
Posted: Sun Mar 20, 2005 2:34 am Post subject: (No subject) |
|
|
ya, its inside of a loop, heres the whole program
code: |
%variable declaration
View.Set ("graphics:400;300,title:Uncle Worm Score: 0")
var food1 : int
var food2 : int
var foodSize : int
var box1 : int := 0
var box2 : int := maxy
var box3 : int := maxx
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 score : int := 0
var newMaxX : int := 400 %innitial screen dimensions (x co-ords)
var newMaxY : int := 300 %innitial screen dimensions (y co-ords)
var levelUp : int := 10 %decrease in screen dimensions upon completion of level
var scoreLevel : int := 10
%gives time for user to get ready
loop
locate (9, 18)
put "Starting in...", countdown - 1
delay (300)
countdown := countdown - 1
cls
exit when countdown = 0
end loop
%creates food in random locations
procedure food
randint (food1, 1, 395) %random food location (but not in the walls)
randint (food2, 1, 295) %random food location (but not in the walls)
randint (foodSize, 2, 10) %random food size
drawfilloval (food1, food2, foodSize, foodSize, 2)
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, box2, box3, 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
food %when collision detected food is redrawn
end if
%NEXT LEVEL
if score = scoreLevel
then
drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 4)
scoreLevel += 10
exit when whatdotcolour (ballx1+ballsize,bally1+ballsize)=4
end if
end loop
/*
View.Set ("graphics:" + intstr (newMaxX-levelUp) + ";" + intstr (newMaxY-levelUp) + ",title:Uncle Worm Score: " + intstr (score))
*/
View.Update
|
|
|
|
|
|
|
Cervantes
|
Posted: Sun Mar 20, 2005 8:55 am Post subject: (No subject) |
|
|
You probably want your View.Update to be inside your loop.
That should work. The reason yours was not working was because a.) you were adding to scoreLevel, which means as soon as you eat an apple and get your score to equal scoreLevel, score level goes up. So you are only inside that if statement when you touch an apple. And when you touch an apple, you aren't touching the exit. b.) your collision detection has problems. whatdotcolour can be effective, but you need to use it better. See, you were checking for a collision with the top right edge of the player (ballx1 + ballsize, bally1 + ballsize). I changed it so that you are checking with the top setion (because the exit is at the top of the screen). But, really, you need to check all around your player. That
involves either some trig and a for loop, or a lot of if statements.
Also, notice that I changed if score = scoreLevel to if score >= scoreLevel. The way you had it, you could only get to the exit if your score was exactly = to score level. If you ate two apples, then went to the exit, you'd die. |
|
|
|
|
|
Mr. T
|
Posted: Sun Mar 20, 2005 2:34 pm Post subject: (No subject) |
|
|
2 probelms: 1. when the exit point opens food is still being created (it shouldnt be) 2. after entering the next level (in which the screen dimensions are decreased) after eating one piece of food, the screen reverts to its original state
----------------------------
code: |
%variable declaration
View.Set ("graphics:400;300,title:Uncle Worm Score: 0")
var food1 : int
var food2 : int
var foodSize : int
var box1 : int := 0
var box2 : int := maxy
var box3 : int := maxx
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 score : int := 0
var newMaxX : int := 400 %innitial screen dimensions (x co-ords)
var newMaxY : int := 300 %innitial screen dimensions (y co-ords)
var levelUp : int := 10 %decrease in screen dimensions upon completion of level
var scoreLevel : int := 50
var foodBoolean :boolean
%gives time for user to get ready
loop
locate (9, 18)
put "Starting in...", countdown - 1
delay (300)
countdown := countdown - 1
cls
exit when countdown = 0
end loop
%creates food in random locations
procedure food
randint (food1, 1, 395) %random food location (but not in the walls)
randint (food2, 1, 295) %random food location (but not in the walls)
randint (foodSize, 2, 10) %random food size
drawfilloval (food1, food2, foodSize, foodSize, 2)
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, box2, box3, 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
food
end if
%NEXT LEVEL
if score >= scoreLevel
then
drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 4)
end if
if whatdotcolour (ballx1+ballsize,bally1+ballsize)=4
then View.Set ("graphics:" + intstr (newMaxX-levelUp) + ";" + intstr (newMaxY-levelUp) + ",title:Uncle Worm Score: " + intstr (score))
ballx1:=200
bally1:=200
food
scoreLevel:=score+50
end if
end loop
View.Update
|
|
|
|
|
|
|
Bacchus
|
Posted: Sun Mar 20, 2005 8:34 pm Post subject: (No subject) |
|
|
at the beginning of ur game make a boolean variable
code: | var makeFood:boolean:=true |
Set the boolean to false to turn the food off
code: | %NEXT LEVEL
if score >= scoreLevel then
drawfillbox ((maxx div 2) - 10, maxy, (maxx div 2) + 10, maxy - 5, 4)
makeFood:=false
end if |
and in ur place food proc do a check to make sure to place it
code: | procedure food
if makeFood then
randint (food1, 1, 395) %random food location (but not in the walls)
randint (food2, 1, 295) %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 |
|
|
|
|
|
|
Mr. T
|
Posted: Sun Mar 20, 2005 8:40 pm Post subject: (No subject) |
|
|
doesnt seem to work...it still makes food when the exit point opens....and for some reason, when u eat the food... u get 100 points more ? |
|
|
|
|
|
Bacchus
|
Posted: Sun Mar 20, 2005 8:45 pm Post subject: (No subject) |
|
|
code: | %variable declaration
View.Set ("graphics:400;300,title:Uncle Worm Score: 0")
var food1 : int
var food2 : int
var foodSize : int
var box1 : int := 0
var box2 : int := maxy
var box3 : int := maxx
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 score : int := 0
var newMaxX : int := 400 %innitial screen dimensions (x co-ords)
var newMaxY : int := 300 %innitial screen dimensions (y co-ords)
var levelUp : int := 10 %decrease in screen dimensions upon completion of level
var scoreLevel : int := 50
var foodBoolean : boolean := true
%gives time for user to get ready
loop
locate (9, 18)
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 foodBoolean then
randint (food1, 1, 395) %random food location (but not in the walls)
randint (food2, 1, 295) %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, box2, box3, 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)
foodBoolean := false
end if
if whatdotcolour (ballx1 + ballsize, bally1 + ballsize) = 4
then
View.Set ("graphics:" + intstr (newMaxX - levelUp) + ";" + intstr (newMaxY - levelUp) + ",title:Uncle Worm Score: " + intstr (score))
ballx1 := 200
bally1 := 200
foodBoolean := true
food
scoreLevel := score + 50
end if
end loop |
|
|
|
|
|
|
Sponsor Sponsor
|
|
|
Mr. T
|
Posted: Sun Mar 20, 2005 8:51 pm Post subject: (No subject) |
|
|
notice however...when u do that...the scoring gets really messed up, and once u get to the next level...there are two walls missing, and when u crash into the wall the ball isnt in the centre of the crash point....strange...? |
|
|
|
|
|
Bacchus
|
Posted: Sun Mar 20, 2005 8:53 pm Post subject: (No subject) |
|
|
i dunno i was just showing you how to make it so the food wont show when u can goto the next lvl. if the scoreing is screwed, search in ur code for everyplace that the score gets added to. also r u sure that the food isnt appearing on the snake guy? |
|
|
|
|
|
|
|