forked from DPriceDev/Megadrive-Maze
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added new sprites for player, updated character and joystick classes …
…to work together and move the player.
- Loading branch information
Showing
12 changed files
with
195 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,9 @@ | ||
#ifndef _RES_RESOURCE_H_ | ||
#define _RES_RESOURCE_H_ | ||
|
||
extern const SpriteDefinition PlayerWalkingSprite; | ||
extern const SpriteDefinition PlayerIdleDownSprite; | ||
extern const SpriteDefinition PlayerIdleUpSprite; | ||
extern const Image tilemap; | ||
|
||
#endif // _RES_RESOURCE_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,4 @@ | ||
IMAGE tilemap "tilemaps/tilemap.bmp" 0 | ||
IMAGE tilemap "tilemaps/tilemap.bmp" 0 | ||
SPRITE PlayerWalkingSprite "sprites/PlayerWalkingHorizontalSprite.bmp" 1 1 FAST 15 | ||
SPRITE PlayerIdleDownSprite "sprites/PlayerIdleDownSprite.bmp" 1 1 FAST 15 | ||
SPRITE PlayerIdleUpSprite "sprites/PlayerIdleUpSprite.bmp" 1 1 FAST 15 |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
// | ||
// Created by urban on 17/07/2020. | ||
// | ||
|
||
#include "character.h" | ||
#include "string.h" | ||
|
||
struct Character *character; | ||
|
||
struct Character *initCharacter() { | ||
character = MEM_alloc(sizeof *character); | ||
character->mX = 7 * 8; | ||
character->mY = 7 * 8; | ||
character->mIdleDownSprite = SPR_addSprite(&PlayerIdleDownSprite, character->mX, character->mY, TILE_ATTR(PAL1, 1, 0, 0)); | ||
character->mWalkingSprite = SPR_addSprite(&PlayerWalkingSprite, -8, -8, TILE_ATTR(PAL1, 1, 0, 0)); | ||
character->mIdleUpSprite = SPR_addSprite(&PlayerIdleUpSprite, -8, -8, TILE_ATTR(PAL1, 1, 0, 0)); | ||
struct MovementVector vector = {0, 0 }; | ||
character->mMovementVector = vector; | ||
character->mLookDirection = LOOK_DOWN; | ||
return character; | ||
} | ||
|
||
void characterJoystick(struct JoystickAction *joystickAction) { | ||
switch (joystickAction->mButton) { | ||
case LEFT: | ||
if(joystickAction->mAction == PRESSED) { | ||
character->mMovementVector.mX = -1; | ||
} else { | ||
character->mMovementVector.mX = 0; | ||
} | ||
break; | ||
case RIGHT: | ||
if(joystickAction->mAction == PRESSED) { | ||
character->mMovementVector.mX = 1; | ||
} else { | ||
character->mMovementVector.mX = 0; | ||
} | ||
break; | ||
case UP: | ||
if(joystickAction->mAction == PRESSED) { | ||
character->mMovementVector.mY = -1; | ||
} else { | ||
character->mMovementVector.mY = 0; | ||
} | ||
break; | ||
case DOWN: | ||
if(joystickAction->mAction == PRESSED) { | ||
character->mMovementVector.mY = 1; | ||
} else { | ||
character->mMovementVector.mY = 0; | ||
} | ||
break; | ||
} | ||
} | ||
|
||
void characterTick() { | ||
updatePosition(); | ||
} | ||
|
||
void setLookDirectionFromMovementVector() { | ||
if(character->mMovementVector.mX > 0) { | ||
character->mLookDirection = LOOK_RIGHT; | ||
} else if(character->mMovementVector.mX < 0) { | ||
character->mLookDirection = LOOK_LEFT; | ||
} else if(character->mMovementVector.mY < 0) { | ||
character->mLookDirection = LOOK_UP; | ||
} else { | ||
character->mLookDirection = LOOK_DOWN; | ||
} | ||
} | ||
|
||
void updatePosition() { | ||
character->mX += character->mMovementVector.mX; | ||
character->mY += character->mMovementVector.mY; | ||
setLookDirectionFromMovementVector(); | ||
|
||
switch (character->mLookDirection) { | ||
case LOOK_LEFT: | ||
SPR_setHFlip(character->mWalkingSprite, 0); | ||
SPR_setPosition(character->mWalkingSprite, character->mX, character->mY); | ||
SPR_setPosition(character->mIdleUpSprite, -8, -8); | ||
SPR_setPosition(character->mIdleDownSprite, -8, -8); | ||
break; | ||
case LOOK_UP: | ||
SPR_setPosition(character->mIdleUpSprite, character->mX, character->mY); | ||
SPR_setPosition(character->mIdleDownSprite, -8, -8); | ||
SPR_setPosition(character->mWalkingSprite, -8, -8); | ||
break; | ||
case LOOK_RIGHT: | ||
SPR_setHFlip(character->mWalkingSprite, 1); | ||
SPR_setPosition(character->mWalkingSprite, character->mX, character->mY); | ||
SPR_setPosition(character->mIdleDownSprite, -8, -8); | ||
SPR_setPosition(character->mIdleUpSprite, -8, -8); | ||
break; | ||
case LOOK_DOWN: | ||
SPR_setPosition(character->mIdleDownSprite, character->mX, character->mY); | ||
SPR_setPosition(character->mIdleUpSprite, -8, -8); | ||
SPR_setPosition(character->mWalkingSprite, -8, -8); | ||
break; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters