2 Replies - 761 Views - Last Post: 06 April 2013 - 10:01 AM Rate Topic: -----

#1 Bawnawgwa  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 123
  • Joined: 21-January 13

Animation issues with my 2d game. Any help?

Posted 23 March 2013 - 11:46 AM

I am new to programming and am using graphics.h for this game. It is a basic game with 2d graphics (like old pokemon style graphics).

Here is my code so far:
void runGame(){
	readimagefile("PIX\\Landscape.jpg", 0, 0, 800, 800);
	
	while(1 == 1){
		moveCharacter();
		moveMonster();
	}
}
void moveCharacter(){
	int move = 0;
	int size = imagesize(0, 0, 800, 800);
	void *background = malloc(size);
	getimage(0, 0, 800, 800, background);

	readimagefile("PIX\\Character\\down_still.gif",x9,y9,x9+50,y9+50);
	thunderClaw();
	specialAttack();
	if(kbhit()){

	if(getch()== 'd'){
		move = 1;
		}
	if(getch()== 'a'){
		move =  3;
		}
	if(getch()== 'w'){
		move = 2;
		}
	if(getch()== 's'){
		move = 4;
		}
	}
	
	switch (move){
		
	case 1://left

		readimagefile("PIX\\Character\\left_r.gif",x9,y9,x9+50,y9+50);Sleep(15);
		x9 = x9 + 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\left_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
		x9 = x9 + 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\left_l.gif",x9,y9,x9+50,y9+50);Sleep(15);
		x9 = x9 + 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\left_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
		x9 = x9 + 5;
		putimage(0, 0, background, COPY_PUT);
		break;

	case 2://up

		readimagefile("PIX\\Character\\up_r.gif",x9,y9,x9+50,y9+50);Sleep(15);
		y9 = y9 - 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\up_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
		y9 = y9 - 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\up_l.gif",x9,y9,x9+50,y9+50);Sleep(15);
		y9 = y9 - 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\up_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
		y9 = y9 - 5;
		putimage(0, 0, background, COPY_PUT);
		break;

	case 3://right

		readimagefile("PIX\\Character\\right_r.gif",x9,y9,x9+50,y9+50);Sleep(15);
		x9 = x9 - 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\right_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
		x9 = x9 - 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\right_l.gif",x9,y9,x9+50,y9+50);Sleep(15);
		x9 = x9 - 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\right_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
		x9 = x9 - 5;
		putimage(0, 0, background, COPY_PUT);
		break;


	case 4://down
		 
		readimagefile("PIX\\Character\\down_l.gif",x9,y9,x9+50,y9+50);Sleep(15);
		y9 = y9 + 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\down_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
		y9 = y9 + 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\down_r.gif",x9,y9,x9+50,y9+50);Sleep(15);
		y9 = y9 + 5;
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Character\\down_still.gif",x9,y9,x9+50,y9+50);Sleep(15);
		y9 = y9 + 5;
		putimage(0, 0, background, COPY_PUT);
		break;
		}

	}//end function

void thunderClaw(){
	int mx = mousex();
	int my = mousey();

	int size = imagesize(0, 0, 800, 800);
	void *background = malloc(size);
	getimage(0, 0, 800, 800, background);

	if(WM_LBUTTONDOWN){
		getmouseclick(WM_LBUTTONDOWN, mx, my);
		#ifdef SOUNDfx
		PlaySound("SOUNDS\\Electricity_Shock_Sound_Effect.wav", NULL, SND_ASYNC);
		#endif
		readimagefile("PIX\\Thunderclaw\\thunderclaw00.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Thunderclaw\\thunderclaw01.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Thunderclaw\\thunderclaw0.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Thunderclaw\\thunderclaw.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Thunderclaw\\thunderclaw2.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Thunderclaw\\thunderclaw3.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Thunderclaw\\thunderclaw4.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
		putimage(0, 0, background, COPY_PUT);
		readimagefile("PIX\\Thunderclaw\\thunderclaw5.gif", mx-25, my-25, mx+25, my+25);Sleep(80);
		putimage(0, 0, background, COPY_PUT);
	}
}

void specialAttack(){
	int size = imagesize(0, 0, 800, 800);
	void *background = malloc(size);
	getimage(0, 0, 800, 800, background);
		if(kbhit()){
			getch();
		if(getch() == '1'){
			#ifdef SOUNDfx
			PlaySound("SOUNDS\\Special_attack2.0.wav", NULL, SND_ASYNC);
			#endif
			readimagefile("PIX\\Special Attack\\Special00.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special01.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special03.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special04.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special05.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special06.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special07.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special08.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special09.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special10.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special11.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special12.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special13.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special14.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special15.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special16.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special17.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special18.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special19.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special20.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special21.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special22.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special23.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special24.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special25.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
			readimagefile("PIX\\Special Attack\\Special26.gif", x9-70, y9+60, x9+150, y9+250);Sleep(100);
			putimage(0,0, background, COPY_PUT);
		} //end if(getch())
	} //end kbhit()
} //end function

int Monster1(int direction){
	int x2 = 400;
	int y2 = 400;
	int size = imagesize(0, 0, 800, 800);
	void *background = malloc(size);
	getimage(0, 0, 800, 800, background);
	
switch (direction){

case 0:
	direction == 0;
	y2 = y2+1; 
	break;

case 1:
	direction == 1;
	y2 = y2+1; 
	x2 = x2+1;
	break;

case 2:
	direction == 2;
	x2 = x2+1; 
	break;

case 3:
	direction == 3;
	x2 = x2+1;
	y2 = y2-1; 
	break;

case 4:
	direction == 4;
	y2 = y2-1; 
	break;

case 5:
	direction == 5;
	y2 = y2-1;
	x2 = x2-1;
	break;

case 6:
	direction == 6;
	x2 = x2-1; 
break;

case 7:
	direction == 7;
	x2 = x2-1; 
	y2 = y2+1;
break;

}//switch ends

readimagefile("PIX\\Monster_down_l.gif", x2, y2, x2+50, y2+50);
putimage(0, 0, background, COPY_PUT);

//collision detected
if (x2 > 750 || y2 > 750 || x2 < 50 || y2 < 50) return 1;

else return 0;
}

int moveMonster(){

int directions = 1;
int collisions = 0;

while(1){

collisions = Monster1(directions);
if(collisions){ directions--;
if(directions < 0 ) directions = 7;

}
Sleep(3);//Changed this to sleep command and Sleep(3) is a lovely speed.
//cleardevice();//Gets rid of trail
//if (kbhit()) {getch(); break;}

}//while

return 0;}


My problems are thus:
1)currently I am getting unhandled exceptions when I use my character moving keys a few times.
2)Thunderclaw constantly goes off in the upper left hand corner slowing down movement (I don't get why... I thought I have it set up it should only go off when you left click and where you left click...)
3)Monster is not working at all... I cannot get the picture to even come on screen... We used the very same program to animate a ball to bounce around the screen, so I used it for the monster and only changed the image it reads in to get a monster to move about the screen and bounce off the edges... But it is not working one bit lol.

Thanks for any help in solving these issues :P/>

P.S. I feel I am utilizing putimage() wrong... and maybe that is the reason for thunderclaw not behaving properly... If I am using it wrong, does anyone have good suggestion for covering each image with background image immediately after it comes on screen? If that makes sense.

Is This A Good Question/Topic? 0
  • +

Replies To: Animation issues with my 2d game. Any help?

#2 frostraver  Icon User is offline

  • D.I.C Head

Reputation: 11
  • View blog
  • Posts: 93
  • Joined: 11-September 12

Re: Animation issues with my 2d game. Any help?

Posted 06 April 2013 - 07:05 AM

It seems like you're trying to animate your sprites with switching textures, well, with actual different files. It's much better to use regions on a spritesheet. Than you can use a single position of your character and you only need to change the region of your texture whatever you do.

If you get Unhandled Exceptions you probably call an object that isn't initialized or something.

I don't know if this'll be of any help. Be sure to try using Spritesheets and clean up your code a bit so it's easier to read through. (and use as many comments as possible. Maybe you can understand your own code but it's harder for other people to understand it)

Kind regards!
Was This Post Helpful? 0
  • +
  • -

#3 anonymous26  Icon User is offline

  • D.I.C Lover

Reputation: 1
  • View blog
  • Posts: 3,638
  • Joined: 26-November 10

Re: Animation issues with my 2d game. Any help?

Posted 06 April 2013 - 10:01 AM

View PostBawnawgwa, on 23 March 2013 - 03:46 PM, said:

My problems are thus:
1)currently I am getting unhandled exceptions when I use my character moving keys a few times.

What specifically are the unhandled exceptions? We need the specific message(s).

View PostBawnawgwa, on 23 March 2013 - 03:46 PM, said:

2)Thunderclaw constantly goes off in the upper left hand corner slowing down movement (I don't get why... I thought I have it set up it should only go off when you left click and where you left click...)

Well think about it. It is because you are not limiting where Thunderclaw can go. If you are you need to make sure that code is being hit.

View PostBawnawgwa, on 23 March 2013 - 03:46 PM, said:

3)Monster is not working at all... I cannot get the picture to even come on screen... We used the very same program to animate a ball to bounce around the screen, so I used it for the monster and only changed the image it reads in to get a monster to move about the screen and bounce off the edges... But it is not working one bit lol.

When you have unhandled exceptions your program will not function correctly. The meaning of an unhandled exception is that your program has encountered a situation that you haven't told it how to handle or otherwise avoid. We need to know what that is before moving on.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1