Trying to make a pacman game. Pls help
Author |
Message |
Jynx101
|
Posted: Sun May 21, 2017 3:34 pm Post subject: Trying to make a pacman game. Pls help |
|
|
What is it you are trying to achieve?
I'm trying to have pacman stop at the walls, but no luck
What is the problem you are having?
Describe what you have tried to solve this problem
I tried using whatdotcolor, but it's not responding at all.
Post any relevant code (You may choose to attach the file instead of posting the code if it is too long)
<Answer Here>
Turing: |
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")
Draw.Text ("PACMAN", 125, 400, font, yellow)
Draw.Text ("Classic", 232, 300, font1, brightblue)
Draw.Text ("Survival", 214, 250, font1, brightred)
Draw.Text ("Maze", 251, 200, font1, green)
Draw.Text ("Hell", 269, 150, font1, purple)
procedure Classic
setscreen ("graphics:448,576,offscreenonly,nobuttonbar")
View.Set ("offscreenonly")
var chars : array char of boolean
var xlocation, ylocation, xdirection, ydirection, r : int
var pacstate : boolean
xlocation := 0
ylocation := 0
xdirection := 225
ydirection := 150
r := 11
pacstate := true
var background := Pic.FileNew ("PacmanBack.bmp")
loop
Pic.Free (background )
background := Pic.FileNew ("PacmanBack.bmp")
Pic.Draw (background, 0, 0, picMerge)
drawfillbox (100, 100, 200, 200, blue)
Input.KeyDown (chars )
if chars (KEY_RIGHT_ARROW) then
if pacstate = true then %Mouth Closed
drawfilloval (xdirection, ydirection, r, r, yellow)
xdirection := xdirection + 5
pacstate := false %Changes it so the next time around it's open
else %Mouth Open
drawfilloval (xdirection, ydirection, r, r, yellow)
drawfillarc (xdirection, ydirection, r, r, 310, 40, black)
xdirection := xdirection + 5
pacstate := true %Changes it so the next time the mouth is closed
end if
elsif chars (KEY_LEFT_ARROW) then
if pacstate = true then
drawfilloval (xdirection, ydirection, r, r, yellow)
xdirection := xdirection - 5
pacstate := false
else
drawfilloval (xdirection, ydirection, r, r, yellow)
drawfillarc (xdirection, ydirection, r, r, 130, 210, black)
xdirection := xdirection - 5
pacstate := true
end if
elsif chars (KEY_DOWN_ARROW) then
if pacstate = true then
drawfilloval (xdirection, ydirection, r, r, yellow)
ydirection := ydirection - 5
pacstate := false
else
drawfilloval (xdirection, ydirection, r, r, yellow)
drawfillarc (xdirection, ydirection, r, r, 230, 310, black)
ydirection := ydirection - 5
pacstate := true
end if
elsif chars (KEY_UP_ARROW) then
if pacstate = true then
drawfilloval (xdirection, ydirection, r, r, yellow)
ydirection := ydirection + 5
pacstate := false
else
drawfilloval (xdirection, ydirection, r, r, yellow)
drawfillarc (xdirection, ydirection, r, r, 70, 120, black)
ydirection := ydirection + 5
pacstate := true
end if
else
drawfilloval (xdirection, ydirection, 12, 12, yellow) %Draws Pacman when no keys are pressed
end if
View.UpdateArea (xdirection - 45, ydirection - 45, xdirection + 45, ydirection + 45) %Updates just the area to reduce lag
if xdirection = 1 and whatdotcolor (xlocation + 11, ylocation ) = blue then
cls
elsif xdirection = - 1 and whatdotcolor (xlocation - 11, ylocation ) = blue then
cls
elsif ydirection = 1 and whatdotcolor (xlocation, ylocation + 11) = blue then
cls
elsif ydirection = - 1 and whatdotcolor (xlocation, ylocation - 11) = blue then
cls
end if
delay (12)
end loop
end Classic
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
|
Please specify what version of Turing you are using
4.1.1 |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Insectoid
|
Posted: Sun May 21, 2017 3:51 pm Post subject: RE:Trying to make a pacman game. Pls help |
|
|
code: | if xdirection = 1 and whatdotcolor (xlocation + 11, ylocation) = blue then
cls
elsif xdirection = -1 and whatdotcolor (xlocation - 11, ylocation) = blue then
cls
elsif ydirection = 1 and whatdotcolor (xlocation, ylocation + 11) = blue then
cls
elsif ydirection = -1 and whatdotcolor (xlocation, ylocation - 11) = blue then
cls
end if |
In English, this code says 'if we hit a wall, clear the screen'. Is that really what you want to happen? I would think that if you hit a wall, you'd want to stop moving, or change direction, or lose the game, or something. Clearing the screen essentially does nothing, because when you restart the loop, it all gets drawn again anyway. In fact, you should be erasing everything at the end of the loop regardless! |
|
|
|
|
|
Jynx101
|
Posted: Sun May 21, 2017 3:54 pm Post subject: RE:Trying to make a pacman game. Pls help |
|
|
Ohhhh. Ok. So if I were to put in another command, it would do so otherwise? |
|
|
|
|
|
Jynx101
|
Posted: Sun May 21, 2017 4:10 pm Post subject: RE:Trying to make a pacman game. Pls help |
|
|
Wait, still doesn't work. I made pacman go into something blue, but it doesn't do anything Insectoid, even with a different command. Does it have to do with where I place the if statement? |
|
|
|
|
|
Insectoid
|
Posted: Sun May 21, 2017 5:22 pm Post subject: RE:Trying to make a pacman game. Pls help |
|
|
It has to do with a lot of things. Hard to tell without seeing your code. It's governing movement though, so it's very likely the code should be close to your other movement code.
You can't just slap code anywhere and hope it works, because it won't. Ever. You need to put a lot of thought into what you're trying to do and what you're actually doing. |
|
|
|
|
|
Jynx101
|
Posted: Sun May 21, 2017 11:48 pm Post subject: Re: Trying to make a pacman game. Pls help |
|
|
Yeah, thanks. I got it to work now, after toying around with it a bit. Although, even after fixing it, I did the command drawline, and the pacman doesn't stop. Why? |
|
|
|
|
|
Insectoid
|
Posted: Mon May 22, 2017 1:12 pm Post subject: RE:Trying to make a pacman game. Pls help |
|
|
I don't know, there could be a thousand reasons. Without seeing your code I have no way of knowing. |
|
|
|
|
|
|
|