Hello,
My name is Troy and I'm new here. This is by far the most fun game engine I've ever had the pleasure of using. I've been having fun making this little Pac-man game for my first working project. I like to start small but I'm having a bit of a problem. I can't get Sprite Collision or Sprite Hit to work for the life of me.
So I've decided I will have to just make an alternative collision detector function by adding a square range around my sprite that's as big as it's height/width and return a 1 when something intersects with it. But here is my problem, I don't know how to accept a sprite as one of my function's arguments.
I come from a Visual Studio background so I'm most used to doing something along the lines of:
MyFunction(X as Integer, Y as Integer, MySprite as Sprite)
Here is my code so far:
Rem Project: Pac-Man
Rem Created: Sunday, January 01, 2012
Rem ***** Main Source File *****
Sync On
Sync Rate 30
Do
CLS
If Button(275,198,"Start")=1 Then Goto LoadContent
If Button(275,240,"Quit")=1 Then END
Sync
Loop
LoadContent:
Load Image "pacman-up.png",1
Load Image "pacman-down.png",2
Load Image "pacman-left.png",3
Load Image "pacman-right.png",4
Load Image "ghost.png",5
Global PosX = 50
Global PosY = 50
Global Speed# = 2.0
Global LastDir = 0
Global CurrentDir = 1
Goto Main_Loop
Main_Loop:
Ink RGB(255,255,255),0
PopulateSprites()
Do
CheckInput()
RefreshCharacter()
Sync
Loop
Function CheckInput()
Select ScanCode()
Case 17 Rem W/Up
LastDir = CurrentDir
CurrentDir = 1
Dec PosY,Speed#
EndCase
Case 31 Rem S/Down
LastDir = CurrentDir
CurrentDir = 2
Inc PosY,Speed#
EndCase
Case 30 Rem A/Left
LastDir = CurrentDir
CurrentDir = 3
Dec PosX,Speed#
EndCase
Case 32 Rem D/Right
LastDir = CurrentDir
CurrentDir = 4
Inc PosX,Speed#
EndCase
EndSelect
EndFunction
Function RefreshCharacter()
Select CurrentDir
Case 1
Set Sprite Image 1,1
EndCase
Case 2
Set Sprite Image 1,2
EndCase
Case 3
Set Sprite Image 1,3
EndCase
Case 4
Set Sprite Image 1,4
EndCase
EndSelect
Paste Sprite 1, PosX, PosY
EndFunction
Function PopulateSprites()
Sprite 1, PosX,PosY,4
Sprite 5,196,100,5
Sprite 4,164,100,5
Sprite 3,132,100,5
Sprite 2,100,100,5
GhostDensity# = 200
Hide Sprite 1
Set Sprite Alpha 2,GhostDensity#
Set Sprite Diffuse 2,255,0,0
Set Sprite Alpha 3,GhostDensity#
Set Sprite Diffuse 3,255,127,0
Set Sprite Alpha 4,GhostDensity#
Set Sprite Diffuse 4,255,0,127
Set Sprite Alpha 5,GhostDensity#
Set Sprite Diffuse 5,0,127,255
EndFunction
function Button(x1,y1,WORDS$)
Pressed=0
x2=Text Width(WORDS$)
y2=Text Height(WORDS$)
if mousex()>x1 and mousex()<x1+x2
if mousey()>y1-y2 and mousey()<y1+y2
Pressed=1
endif
endif
if pressed=1 then ink rgb(255,255,0),0 else ink rgb(255,255,255),0
if pressed=1
Pressed=Mouseclick()
else
pressed = 0
endif
text x1,y1,WORDS$
endfunction pressed
Function MyCollision(x1,y1, ?)
EndFunction
I only include all of it so if anyone sees fit they could possibly instruct me on any mistakes I've made as i'm open to ideas because I am new to all this. My main programming languages are C# and Visual Basic but I find DarkBASIC to be very fun
I haven't failed 1,000 times! I've just found 1,000 ways something won't work.