-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathplayer.c
More file actions
87 lines (79 loc) · 2.65 KB
/
player.c
File metadata and controls
87 lines (79 loc) · 2.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
/*****************************************************************
* Project: c64 shooter
*
* $Revision$
* $Date$
* $Author$
*****************************************************************
*
* Copyright(c) 2016 Andreas Rueckert <arueckert67@t-online.de>
*
* This file may be licensed under the terms of of the
* GNU General Public License Version 2 (the ``GPL'').
*
* Software distributed under the License is distributed
* on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
* express or implied. See the GPL for the specific language
* governing rights and limitations.
*
* You should have received a copy of the GPL along with this
* program. If not, go to http://www.gnu.org/licenses/gpl.html
* or write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*
*****************************************************************/
#include "player.h"
#include "shot.h"
#include "sprite.h"
#include <stdbool.h>
#include <stdio.h>
/*
* Horizontal position of the player.
*/
unsigned int playerXpos = PLAYER_X_POS_DEFAULT;
/*
* Vertical position of the player.
*/
unsigned char playerYpos = PLAYER_Y_POS_DEFAULT;
/**
* Initialize the player.
*
* @param level The current level.
*
* @return true, if the player was initialized. False otherwise.
*/
char playerInitialize( unsigned char level) {
spriteSetPosition( 160, playerYpos, 0); /* Set a initial position. */
spriteEnable(true, 0); /* Make the sprite visible. */
return true;
}
/**
* Load the player data for a given level.
*
* @param level The next level to play.
*
* @return true, if the data were successfully loaded, false otherwise.
*/
char playerLoad( unsigned char level) {
// Init the player sprite.
/* if( ! spriteLoad( PLAYER_SPRITE_FILE, (unsigned char *)(0xf000), 1, 0)) { */
if( ! spriteLoad( PLAYER_SPRITE_FILE, spriteGetMemorySlot(), 1, 0)) {
#ifdef DEBUG
printf( "Cannot load sprite 0");
#endif
return false;
}
spriteSetColor( 10, 0); /* Set the color of sprite 0 to 10 (red). */
spriteSetMultiColor( 15, 0); /* Set sprite multicolor 0 to 15 (light grey). */
spriteSetMultiColor( 12, 1); /* Set sprite multicolor 1 to 12 (darker grey). */
}
/**
* Move the player sprite.
*/
void playerMove(void) {
if( joystick1isLeft() && (playerXpos > 22)) { spriteSetXposition(--playerXpos,0); }
if( joystick1isRight() && (playerXpos < 324)) { spriteSetXposition(++playerXpos,0); }
if( joystick1isUp() && (playerYpos > 80)) { spriteSetYposition(--playerYpos,0); }
if( joystick1isDown() && (playerYpos < 228)) { spriteSetYposition(++playerYpos,0); }
if( joystick1isFire()) { shotNew( playerXpos, playerYpos); }
}