drawfillbox(168, 264, 280, 327, brightblue)%Box where ghosts are contained drawfillbox(175, 271, 273, 320, black)%Inside box where ghosts are contained drawfillbox(200, 321, 250, 326, white)%Exit part of box for ghosts
drawfilloval(x, y, r, r, yellow)%Draws pacman's body
x := x + 5%Drives him towards the right
pacstate :=false%Changes to open his mouth
ifwhatdotcolor(x + r, y)=brightblueorwhatdotcolor(x + r, y + r)=brightblueorwhatdotcolor(x + r, y - r)=brightbluethen%When it hits something brightblue...
x := x - 5%As a loop, it will then back it up, thus nullfying the movement of pacman endif%A.K.A. Collision Detection
else%When mouth is open
drawfilloval(x, y, r, r, yellow)%Draws pacmans' body drawfillarc(x, y, r, r, 310, 40, black)%Pacmans' mouth
x := x + 5%Changes to open his mouth
pacstate :=true%Changes to close his mouth
var x, y, button :int loop mousewhere(x, y, button) locate(1, 1) if button =1and x > 230and x < 385and y > 300and y < 340then cls
Classic
endif endloop
Please specify what version of Turing you are using
<Answer Here>
4.1.1
Sponsor Sponsor
Insectoid
Posted: Wed May 24, 2017 5:11 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
You are going to need to keep track of every dot somehow. An array will work. Every time you go through the main loop, look at every dot in the array. If it hasn't been eaten yet, draw it. If it has, don't.
The one they call Greed
Posted: Wed May 24, 2017 5:40 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
a Boolean would be able to check if something is true or false, although that might not be the best option for something like this.
Insectoid
Posted: Wed May 24, 2017 6:56 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
A boolean might be exactly the best option for something like this.
The one they call Greed
Posted: Wed May 24, 2017 7:51 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
I would assume it would involve putting the boolean variables into an array and checking each time a dot is touched it turns the boolean false to show it is missing?
Insectoid
Posted: Wed May 24, 2017 7:57 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
That sounds like a good place to start. Why not try it out and see how it goes?
Jynx101
Posted: Wed May 24, 2017 9:20 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
Alright ill see how it goes
Jynx101
Posted: Thu May 25, 2017 12:54 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
Ok, so I'm feeling pretty stupid rn. How dyou drawfilloval in arrays. And how dyou located every dot at a different place?
Sponsor Sponsor
Insectoid
Posted: Thu May 25, 2017 7:50 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
Maybe you need to store more information than just a single boolean then. If every dot needs a place, maybe you should keep track of those places as well.
You can't drawfilloval in an array any more than you can drawfilloval in an int or a string. Drawfilloval takes ints as parameters. Those ints could come from an array though.
The one they call Greed
Posted: Thu May 25, 2017 10:04 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
You need perimeters; x and y, if you can figure out the location for those, store them in an array, you can call them back later when needed.
Jynx101
Posted: Sun May 28, 2017 12:27 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
Ok, i figured that i am not good with arrays and boolean statements, so what i did was i coded every single dot (took a lot less than i though) and trying to do drawfilloval behind pacman so that it would erase the dots, but its not overlapping.
The code is the exact same but:
%Starting Screen
setscreen ("graphics:600;600")
drawfillbox (0, 0, maxx, maxy, black)
var font, font1 : int
font := Font.New ("Broadway:56:bold")
font1 := Font.New ("Broadway:30:bold")
setscreen ("graphics:448,576,offscreenonly,nobuttonbar")
View.Set ("offscreenonly")
var chars : array char of boolean
var x, y, r, p, c : int
var pacstate, dots : boolean
drawfillbox (maxx - 87, 456, maxx - 40, 487, brightblue) %Top far right box
drawfillbox (maxx - 82, 461, maxx - 45, 482, black) %Inside top far right box
drawfillbox (40, 408, 87, 423, brightblue) %Far left small box
drawfillbox (45, 413, 82, 418, black) %Inside far left small box
drawfillbox (120, 311, 136, 423, brightblue) %Left vertical T
drawfillbox (120, 360, 183, 375, brightblue) %Left horizontal T
drawfillbox (125, 316, 131, 418, black) %Inside lefr vertical T
drawfillbox (125, 365, 178, 370, black) %Inside left horizontal T
drawfillbox (168, 408, 279, 423, brightblue) %Middle top horizontal T
drawfillbox (216, 360, 231, 410, brightblue) %Middle top vertical T
drawfillbox (173, 413, 274, 418, black) %Inside middle top horizontal T
drawfillbox (221, 365, 226, 413, black) %Inside middle top vertical T
drawfillbox (maxx - 136, 311, maxx - 120, 423, brightblue) %Right vertical T
drawfillbox (maxx - 183, 360, maxx - 120, 375, brightblue) %Right horizontal T
drawfillbox (maxx - 131, 316, maxx - 125, 418, black) %Inside right vertical T
drawfillbox (maxx - 178, 365, maxx - 125, 370, black) %Inside right horizontal T
drawfillbox (maxx - 87, 408, maxx - 40, 423, brightblue) %Far right small box
drawfillbox (maxx - 82, 413, maxx - 45, 418, black) %Inside far right small box
drawfillbox (168, 264, 280, 327, brightblue) %Box where ghosts are contained
drawfillbox (175, 271, 273, 320, black) %Inside box where ghosts are contained
drawfillbox (200, 321, 250, 326, white) %Exit part of box for ghosts
Input.KeyDown (chars)
if chars (KEY_RIGHT_ARROW) then
if whatdotcolor (x + r, y) = white or whatdotcolor (x + r, y + r) = white or whatdotcolor (x + r, y - r) = white then
drawfilloval (x - 2*r, y, r, r, black)
end if
if pacstate = true then %Mouth Closed
drawfilloval (x, y, r, r, yellow) %Draws pacman's body
x := x + 5 %Drives him towards the right
pacstate := false %Changes to open his mouth
if whatdotcolor (x + r, y) = brightblue or whatdotcolor (x + r, y + r) = brightblue or whatdotcolor (x + r, y - r) = brightblue then %When it hits something brightblue...
x := x - 5 %As a loop, it will then back it up, thus nullfying the movement of pacman
end if %A.K.A. Collision Detection
else %When mouth is open
drawfilloval (x, y, r, r, yellow) %Draws pacmans' body
drawfillarc (x, y, r, r, 310, 40, black) %Pacmans' mouth
x := x + 5 %Changes to open his mouth
pacstate := true %Changes to close his mouth
if whatdotcolor (x + r, y) = brightblue or whatdotcolor (x + r, y + r) = brightblue or whatdotcolor (x + r, y - r) = brightblue then
%Radius of pacman hits something brightblue...
x := x - 5 %Backs it up, thus nullifying the movement of pacman
end if
end if
elsif chars (KEY_LEFT_ARROW) then
if pacstate = true then
drawfilloval (x, y, r, r, yellow)
x := x - 5
pacstate := false
if whatdotcolor (x - r, y) = brightblue or whatdotcolor (x - r, y + r) = brightblue or whatdotcolor (x - r, y - r) = brightblue then
x := x + 5
end if
else
drawfilloval (x, y, r, r, yellow)
drawfillarc (x, y, r, r, 130, 210, black)
x := x - 5
pacstate := true
if whatdotcolor (x - r, y) = brightblue or whatdotcolor (x - r, y + r) = brightblue or whatdotcolor (x - r, y - r) = brightblue then
x := x + 5
end if
end if
elsif chars (KEY_DOWN_ARROW) then
if pacstate = true then
drawfilloval (x, y, r, r, yellow)
y := y - 5
pacstate := false
if whatdotcolor (x, y - r) = brightblue or whatdotcolor (x + r, y - r) = brightblue or whatdotcolor (x - r, y - r) = brightblue then
y := y + 5
end if
else
drawfilloval (x, y, r, r, yellow)
drawfillarc (x, y, r, r, 230, 310, black)
y := y - 5
pacstate := true
if whatdotcolor (x, y - r) = brightblue or whatdotcolor (x + r, y - r) = brightblue or whatdotcolor (x - r, y - r) = brightblue then
y := y + 5
end if
end if
elsif chars (KEY_UP_ARROW) then
if pacstate = true then
drawfilloval (x, y, r, r, yellow)
y := y + 5
pacstate := false
if whatdotcolor (x, y + r) = brightblue or whatdotcolor (x - r, y + r) = brightblue or whatdotcolor (x + r, y + r) = brightblue then
y := y - 5
end if
else
drawfilloval (x, y, r, r, yellow)
drawfillarc (x, y, r, r, 70, 120, black)
y := y + 5
pacstate := true
if whatdotcolor (x, y + r) = brightblue or whatdotcolor (x - r, y + r) = brightblue or whatdotcolor (x + r, y + r) = brightblue then
y := y - 5
end if
end if
else
drawfilloval (x, y, 12, 12, yellow) %Draws Pacman when no keys are pressed
end if
delay (40)
View.UpdateArea (x - 45, y - 45, x + 45, y + 45) %Updates pacman's area to reduce lag
end loop
end Classic
%Starting Screen Options
var x, y, button : int
loop
mousewhere (x, y, button)
locate (1, 1)
if button = 1 and x > 230 and x < 385 and y > 300 and y < 340 then
cls
Classic
end if
end loop
Jynx101
Posted: Sun May 28, 2017 12:29 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
Just at the input.keydown part, is the whatdotcolor
Insectoid
Posted: Sun May 28, 2017 1:53 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
You are detecting collisions? with dots when Pacman's forward edge hits the rear edge of the dot. They are not in the same spot, they're only close to each other. Your eraser dot is being drawn where pacman is, not where the dot is.
This method will work, however it will take at least as much effort to get right as the array method, and the only thing you'll learn is how awful this method is. I strongly recommend you go back to arrays, because you will use that method for the rest of your programming career and the lessons you will learn from it are actually useful.
Where did you run into trouble with the array method?
Jynx101
Posted: Sun May 28, 2017 2:58 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
Okay, so first things first:
1. How to use arrays to draw dots, at specific places?
2. Boolean statements, if true, draw dot. If false, then don't. I get that, but again, can't do it without the array.
3. I somewhat get how arrays work, seeing as i read tutorials, but not enough so that i can get this far. If i had an example of a circle "eating" dots, that would be great.
Insectoid
Posted: Sun May 28, 2017 6:14 pm Post subject: RE:Help for Pacman eating dots. Have no idea to do it.
First things first, every dot gets an x and y coordinate. You already have that in your hundreds of draw commands. Let's make two arrays, one for each x, and one for each y:
Var dotX : array 0..100 of int
var dotY : array 0..100 of int
This will give you enough coordinates for 100 dots. Replace 100 with however many dots you have. Fill the array with your coordinates:
dotX (0) := 15
DotY (0) := 15
This creates a dot at (15, 15). Replace those numbers with appropriate coordinates, and repeat for every dot. There's a better way to do this, but for now we'll do it the long tedious way.
Once you've created coordinates for every dot, we can use a loop to draw them:
for i : 0..100
Draw.FillOval (dotX (i), dotY (I), 10, 10, yellow)
End for
Those three lines of code will draw every dot. But we only want to draw dots that haven't been eaten yet, so we'll create another array of boolean to store whether to draw or not:
var dotsEaten : array 0..100 of boolean
And since all of them start out not eaten, we can set everything to false right away:
for i : 0..100
dotsEaten (i) := false
end for
Now inside the draw loop, we'll add an if statement:
if dotsEaten (i) == false then
draw.filloval (dotsX (I), dotsY (i), etc)
end if
Now you only need to figure out how to detect if a dot was eaten, and set that dot to true in the eaten array. It will then no longer be drawn.