ok, i am making a zelda game right now. My problem is Collisions. I've looked through the forums and i can't find anything that works.
Ok, what i want is to have link walk into a tree an be pushed back. I have tried several methods to do this and still no success. What usually happens is link walks through half of the tree and then gets pushed back.
Can anyone show me exactly how to do this?
#include "DarkGDK.h"
void DarkGDK ( void )
{
int x = 10;
int y = 10;
dbSyncOn ( );
dbSyncRate ( 60 );
dbDisableEscapeKey();
dbSetWindowSize(600,480);
dbMaximizeWindow();
dbSetWindowTitle("Legend Of Zelda: Pixels of Time");
dbSetImageColorKey(255,0,255);
dbLoadMusic("lozwrld.mid",1);
dbLoadImage("grass.png",5);
dbCreateAnimatedSprite(1,"spr_link_right_strip6.png",6,1,1);
dbCreateAnimatedSprite(2,"spr_Link_Left_strip6.png",5,1,2);
dbCreateAnimatedSprite(3,"spr_Link_Front_strip8.png",8,1,3);
dbCreateAnimatedSprite(4,"spr_Link_Back_strip7.png",7,1,4);
dbSprite(6,0,0,5);
dbLoadImage("road.png",8);
dbSprite(7,185,240,8);
dbLoadImage("tree.png",9);
dbLoadImage("boundaryX",10);
dbLoadImage("boundaryY",11);
dbSprite(8,140,90,9);
dbSprite(9,300,90,9);
dbSprite(10,140,270,9);
dbSprite(11,300,270,9);
dbSprite(12,0,0,10);
dbSprite(13,0,480,10);
dbSizeSprite(8,150,150);
dbSizeSprite(9,150,150);
dbSizeSprite(10,150,150);
dbSizeSprite(11,150,150);
dbSetSpritePriority(1,100);
dbSetSpritePriority(2,100);
dbSetSpritePriority(3,100);
dbSetSpritePriority(4,100);
while ( LoopGDK ( ) )
{
dbPlayMusic(1);
dbLoopMusic(1);
//link walking right
if(dbKeyState(32) == 1)
{
dbShowSprite(1);
dbRotateSprite(1,90);
x += 3;
dbRotateSprite(1,0);
dbPlaySprite(1,1,6,40);
dbSprite(1,x,y,1);
dbHideSprite(2);
dbHideSprite(3);
dbHideSprite(4);
dbSizeSprite(1,30,30);
}
else
{
dbSetSpriteFrame(1,4);
}
//link walking left
if(dbKeyState(30) == 1)
{
dbShowSprite(2);
dbRotateSprite(2,90);
x -= 3;
dbRotateSprite(2,0);
dbPlaySprite(2,1,5,35);
dbSprite(2,x,y,2);
dbHideSprite(3);
dbHideSprite(1);
dbHideSprite(4);
dbSizeSprite(2,30,30);
}
else
{
dbSetSpriteFrame(2,3);
}
//link walking backward
if(dbKeyState(31) == 1)
{
dbShowSprite(3);
dbRotateSprite(3,-90);
y += 3;
dbRotateSprite(3,0);
dbPlaySprite(3,1,8,40);
dbSprite(3,x,y,3);
dbHideSprite(1);
dbHideSprite(2);
dbHideSprite(4);
dbSizeSprite(3,27,27);
}
else
{
dbSetSpriteFrame(3,2);
}
//link walking forward
if(dbKeyState(17) == 1)
{
dbShowSprite(4);
dbRotateSprite(4,-90);
y -= 3;
dbRotateSprite(4,0);
dbPlaySprite(4,1,7,40);
dbSprite(4,x,y,4);
dbHideSprite(1);
dbHideSprite(2);
dbHideSprite(3);
dbSizeSprite(4,30,30);
}
else
{
dbSetSpriteFrame(4,3);
}
if(dbEscapeKey() == 1)
{
break;
}
dbSync ( );
}
//delete images, sprites
for( int i = 1; i < 1000; i ++)
{
dbDeleteImage(i);
dbDeleteSprite(i);
}
return;
}