Another problem making SDLSurface show

It doesnt have the same solution though hehe.

I just made this new class for my "monster". But the monster is not appearing.

Here is the relevant code

Monster.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Monster::Monster( Environment* GameEnvironment )
{
	graphics = GameEnvironment->graphics;
	monsterRight[0] = graphics->LoadImage( "Monster_Right_0.bmp" );
	monsterRight[1] = graphics->LoadImage( "Monster_Right_1.bmp" );
	monsterRight[2] = graphics->LoadImage( "Monster_Right_2.bmp" );
	monsterRight[3] = graphics->LoadImage( "Monster_Right_3.bmp" );
	monsterLeft[0] = graphics->LoadImage( "Monster_Left_0.bmp" );
	monsterLeft[1] = graphics->LoadImage( "Monster_Left_1.bmp" );
	monsterLeft[2] = graphics->LoadImage( "Monster_Left_2.bmp" );
	monsterLeft[3] = graphics->LoadImage( "Monster_Left_3.bmp" );

	direction = LEFT;
	frame = 0;
	int xPos = 490;
	int health = 100;
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
void Monster::Move( int playerX )
{
	if( playerX < xPos )
	{
		direction = LEFT;
		frame++;
		xVel -= 3;
	}
	else if( playerX > xPos )
	{
		direction = RIGHT;
		frame++;
		xVel += 3;
	}
}

1
2
3
4
5
6
7
void Game::HandleEvents()
{
	...

	player->HandleEvents();
	monster->Move( player->xPos );
}

1
2
3
4
5
6
7
8
void Game::Logic()
{
	... 

	monster->xPos += monster->xVel;

        ...
}

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
void Game::Render()
{
        ...

	if( monster->frame >= 4 )
		monster->frame = 0;

        ...

	// Draw the monster
		if( monster->direction == RIGHT )
			graphics->ApplySurface( monster->xPos, 311, monster->monsterRight[ monster->frame ], graphics->screen );
		else if( monster->direction == LEFT )
			graphics->ApplySurface( monster->xPos, 311, monster->monsterLeft[ monster->frame ], graphics->screen );
	

	graphics->UpdateScreen();
}
Topic archived. No new replies allowed.