Chaoskiller
|
Posted: Tue Oct 27, 2009 10:10 pm Post subject: Collision Help |
|
|
Ok i have a question. I saw the collision tutorial and i realized its a must for borders in pacman. So what i did was instead of using just rectangles or circle collisions, i mixed them together. I have this code for the collision. This is the whole pacman code but u will notice that it stops if you run into the box. I need to know if there is an easier way to do the collision command because as you can see mine is very long for just 1 box. I bolded the stuff related to the collision. Also i am wondering how i can make it so that it wont allow you to move into that border but u can move in other directions.
% Jordan Upiter October 20,2009
% Pacman Game
import GUI
setscreen ("graphics: max, max")
var pacmanx, pacmany, ballx, bally, score, font, font1, rad, x, x1, y1 : int
var move : array char of boolean
pacmanx := 55
pacmany := 360
score := 0
font := Font.New ("Times New Roman:20")
ballx := 125
bally := 360
rad := 25
x := 100
x1 := 150
y1 := 200
% Pacman when moving up
procedure pacmanUP
drawfilloval (pacmanx, pacmany - 10, rad, rad, 7)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
drawfilloval (pacmanx + 10, pacmany + 2, 4, 4, 7)
drawfillarc (pacmanx, pacmany, rad + 1, rad + 1, 45, 135, 7)
delay (50)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
delay (50)
drawfilloval (pacmanx, pacmany, rad, rad, 7)
end pacmanUP
% Pacman when moving right
procedure pacmanRIGHT
drawfilloval (pacmanx - 10, pacmany, rad, rad, 7)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
drawfilloval (pacmanx + 2, pacmany + 10, 4, 4, 7)
drawfillarc (pacmanx, pacmany, rad + 1, rad + 1, 315, 45, 7)
delay (50)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
delay (50)
drawfilloval (pacmanx, pacmany, rad, rad, 7)
end pacmanRIGHT
% Pacman when moving left
procedure pacmanLEFT
drawfilloval (pacmanx + 10, pacmany, rad, rad, 7)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
drawfilloval (pacmanx + 6, pacmany + 6, 4, 4, 7)
drawfillarc (pacmanx, pacmany, rad + 1, rad + 1, 135, 230, 7)
delay (50)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
delay (50)
drawfilloval (pacmanx, pacmany, rad, rad, 7)
end pacmanLEFT
% Pacman when moving down
procedure pacmanDOWN
drawfilloval (pacmanx, pacmany + 10, rad, rad, 7)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
drawfilloval (pacmanx + 6, pacmany + 6, 4, 4, 7)
drawfillarc (pacmanx, pacmany, rad + 1, rad + 1, 225, 310, 7)
delay (50)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
delay (50)
drawfilloval (pacmanx, pacmany, rad, rad, 7)
end pacmanDOWN
procedure Game
cls
colour (10)
locate (4, 77)
put score
% Background fill colour
drawfill (1, 1, 7, 7)
% Dots First Row
drawfillarc (ballx, bally, 7, 7, 0, 360, 42)
drawline (5, 395, 635, 395, 10)
drawline (5, 5, 5, 395, 10)
drawline (5, 5, 600, 5, 10)
drawbox (600, 360, 600, 5, 10)
drawbox (600, 360, 635, 395, 10)
Draw.Text ("Start Here", 6, 375, font, red)
drawline (10, 360, 40, 360, red)
drawline (30, 370, 40, 360, red)
drawline (30, 350, 40, 360, red)
drawfillbox (x, x, x1, y1, grey)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
% User Input
loop
colour (10)
colourback (7)
locate (4, 76)
put score
drawline (5, 395, 635, 395, 10)
drawline (5, 5, 5, 395, 10)
drawline (5, 5, 600, 5, 10)
drawbox (600, 360, 600, 5, 10)
drawbox (600, 360, 635, 395, 10)
Draw.Text ("Start Here", 6, 375, font, red)
drawline (10, 360, 40, 360, red)
drawline (30, 370, 40, 360, red)
drawline (30, 350, 40, 360, red)
drawfilloval (pacmanx, pacmany, rad, rad, 44)
drawfilloval (pacmanx + 6, pacmany + 6, 4, 4, 7)
drawfillbox (x, x, x1, y1, grey)
if pacmanx + rad = x and pacmany < y1 and pacmany > x or pacmanx > x and pacmanx < x1 and pacmany - rad = y1 or pacmanx - rad = x1 and pacmany < y1 and pacmany > x or pacmanx > x and pacmanx <
x1 and pacmany + rad = x then
exit
end if
Input.KeyDown (move)
if move (KEY_UP_ARROW) then
pacmany := pacmany + 5
pacmanUP
end if
if move (KEY_RIGHT_ARROW) then
pacmanx := pacmanx + 5
pacmanRIGHT
end if
if move (KEY_LEFT_ARROW) then
pacmanx := pacmanx - 5
pacmanLEFT
end if
if move (KEY_DOWN_ARROW) then
pacmany := pacmany - 5
pacmanDOWN
end if
if pacmanx = ballx and pacmany = bally then
drawfillarc (617, 377, 7, 7, 0, 360, 42)
score := score + 10
end if
if pacmanx = 575 then
pacmanx := pacmanx - 5
end if
if pacmany = 370 then
pacmany := pacmany - 5
end if
if pacmanx = 30 then
pacmanx := pacmanx + 5
end if
if pacmany = 30 then
pacmany := pacmany + 5
end if
end loop
end Game
% Instructions
procedure instructions
cls
Draw.Text ("Use the arrow keys to move around. ", 150, 280, font, red)
Draw.Text ("Collect balls for 10 points each.", 165, 250, font, red)
Draw.Text ("Do not get eaten by enemies.", 185, 220, font, red)
View.Set ("graphics:639;399,nobuttonbar")
var draw : int := GUI.CreateButtonFull (319, 179, 0, "Start",
Game, 0, '^D', true)
end instructions
View.Set ("graphics:639;399,nobuttonbar")
var draw : int := GUI.CreateButtonFull (200, 199, 0, "Start",
Game, 0, '^D', true)
View.Set ("graphics:639;399,nobuttonbar")
var instruct : int := GUI.CreateButtonFull (300, 199, 0, "Instructions",
instructions, 0, '^D', true)
loop
exit when GUI.ProcessEvent
end loop
[/b] |
|
|