pacman ?
Author |
Message |
gilbamy
|
Posted: Thu May 04, 2006 2:09 pm Post subject: pacman ? |
|
|
alright here is my code now my problem is that the mouth has to change with the up and down and left
%pac.t
%Pac man moves across the screen using the keypad
setscreen ("graphics")
var backg : array 1 .. sizepic (0, 0, 40, 40) of int
var x,y:int
var key:string(1)
x:=40
y:=40
loop
takepic(x-20,y-20,x+20,y+20,backg)
drawfillarc(x,y,20,20,30,330,yellow)
delay(250)
cls
drawfilloval(x,y,20,20,yellow)
getch (key)
drawpic(x-20,y-20,backg,picCopy)
if key ="A" or key="a" then
x:=x-90
elsif key= "D" or key="d" then
x:=x+90
elsif key= "S" or key= "s" then
y:=y-90
elsif key= "W" or key= "w" then
y:=y+90
end if
end loop |
|
|
|
|
|
Sponsor Sponsor
|
|
|
upthescale
|
Posted: Thu May 04, 2006 2:47 pm Post subject: (No subject) |
|
|
Use code tags...and what is your question? |
|
|
|
|
|
Clayton
|
Posted: Thu May 04, 2006 3:08 pm Post subject: (No subject) |
|
|
welcome to compsci. please use [code] tags when posting code, also, we here at compsci are not telepathic (no matter how hard we try) so make sure you give a detailed description of your problem, and we will try to help you out. however, by the look of your code, you are looking to change the angle at which the mouth is at, so what you could do (im assuming you are using actual pictures) is to have multiple pictures (one with the mouth in each direction and one with the mouth closed) and draw them in whichever way you need them to face |
|
|
|
|
|
aldreneo
|
Posted: Thu May 04, 2006 3:20 pm Post subject: (No subject) |
|
|
code: | %pac.t
%Pac man moves across the screen using the keypad
setscreen ("graphics")
var backg : array 1 .. sizepic (0, 0, 40, 40) of int
var x, y : int
var key : string (1)
x := 40
y := 40
loop
takepic (x - 20, y - 20, x + 20, y + 20, backg)
drawfillarc (x, y, 20, 20, 30, 330, yellow)
delay (250)
cls
drawfilloval (x, y, 20, 20, yellow)
getch (key)
drawpic (x - 20, y - 20, backg, picCopy)
if key = "A" or key = "a" then
x := x - 90
elsif key = "D" or key = "d" then
x := x + 90
elsif key = "S" or key = "s" then
y := y - 90
elsif key = "W" or key = "w" then
y := y + 90
end if
end loop
|
|
|
|
|
|
|
Clayton
|
Posted: Thu May 04, 2006 3:39 pm Post subject: (No subject) |
|
|
just re-posting your code isnt going to help us, plz give a detailed description of your problem so we can better help you. |
|
|
|
|
|
TheOneTrueGod
|
Posted: Thu May 04, 2006 4:39 pm Post subject: (No subject) |
|
|
lol superfreak, that was someone else reposting his code with the code tag
Anyways, welcome to comp sci.
In order to change Pac Man's mouth direction, your going to need an angle variable. Basically, when you press "up", you want that angle to be 90. When you press "left" you want that angle to be 180 degrees, and so on. (Right can be 0 or 360 if you know about some basic degree math.)
then, you can use
code: |
drawfillarc(PacX,PacY,PacSize,PacSize,angle + 30,angle - 30,yellow)
|
If your question wasn't about that, and was instead how to animate, i'll answer that question as well.
You want a counter variable, and some basic math knowledge. Start the counter at zero, and increment it each time the main loop executes. Now, instead of
(angle + 30,angle - 30)
You can do:
(angle + counter,angle - counter)
Now, when counter >= 30, you just reset it to zero. Unfortunately, this will cause an unsightly twitch happening with Mr. Man's mouth. So, this is where the basic math comes in. If, instead of resetting counter when it is 30, reset it when it is 60, and instead of just adding counter to angle, do the following:
(angle + abs(counter - 30),angle + abs(counter - 30))
The abs function returns the absolute value of a number (Allways positive).
There is only one bug with this, and that is when counter is 30. PacMan will not be drawn at all . There is an easy way around this, but i'll let you figure it out ;P (Try reversing counter and 30, and thinking about it for a bit.)
Note: In the future, if you want specific help, you will need to post specific questions. Eg:
Bad question: How do i fix my problem? I used vars and they didn't work.
Good question: My program doesn't work. I tried to declare a variable and it gave me an error I don't understand.
Quote:
Initialization value is the wrong type
code: |
var pi : int
x := 3.1415
|
|
|
|
|
|
|
gilbamy
|
Posted: Thu May 04, 2006 9:37 pm Post subject: (No subject) |
|
|
okay my proble is that i have to use the a s d w buttond to control pack man but his mouth has to face up when i hit w and left when i hit a and down when i hit s it already goes towards the left though so how do i do that |
|
|
|
|
|
gilbamy
|
Posted: Fri May 05, 2006 11:48 am Post subject: (No subject) |
|
|
but i have to use the if key crap code so what do i do about the mouth noving part |
|
|
|
|
|
Sponsor Sponsor
|
|
|
Tony
|
Posted: Fri May 05, 2006 2:03 pm Post subject: (No subject) |
|
|
you have to keep track of the direction as well
code: |
if key = "A" or key = "a" then
x := x - 90
direction := up
%where direction is a variable and up is a constant with some unique value
|
then since you know what direction you're facing, you'll know which way you need to draw your picture |
Tony's programming blog. DWITE - a programming contest. |
|
|
|
|
gilbamy
|
Posted: Tue May 09, 2006 11:38 am Post subject: (No subject) |
|
|
you so lost me there what varabile is direction and anyway i need to use
key"A" or "a" then something like Iangle + fangle crap i hate my teaches code |
|
|
|
|
|
gilbamy
|
Posted: Tue May 09, 2006 11:48 am Post subject: (No subject) |
|
|
that direction up does not eork by the way |
|
|
|
|
|
gilbamy
|
Posted: Tue May 09, 2006 11:49 am Post subject: (No subject) |
|
|
that direction up does not work by the way i am so going to kill turing stupid pacman program die die stupid teacher and his stupid programs |
|
|
|
|
|
codemage
|
Posted: Tue May 09, 2006 1:14 pm Post subject: (No subject) |
|
|
Welcome to the wonderful world of programming.
If you're confused, it doesn't necessarily mean that the assignment, your school, computers, etc. are crap. It just means that you're confused.
iangle and fangle are part of the language. They're not crazy ideas that your teacher has thought up. If you don't want to use them, you get to program your own arc drawing procedure.
If in doubt, you can check out the help files for drawing by typing in the command and hitting F9. The examples (that you can actually run) are quite good. |
|
|
|
|
|
gilbamy
|
Posted: Wed May 10, 2006 2:02 pm Post subject: (No subject) |
|
|
if i don't use his stupid code i lose like 24marks out of like 40 |
|
|
|
|
|
|
|