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 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238
| //-----------------------------------------------------------------------------
/**
* Player.cpp
*
* Q[ÌvC[ðsB
*/
//-----------------------------------------------------------------------------
#include "DxLib.h"
#include "..\\Util\\Input.h"
#include "..\\GameSettings.h"
#include "..\\Util\\Math.h"
//-----------------------------------------------------------------------------
// è
//-----------------------------------------------------------------------------
const int PLAYER_WIDTH = 48;
const int PLAYER_HEIGHT = 64;
float PLAYER_SPEED = 3.0f;
//-----------------------------------------------------------------------------
// \¢Ì
//-----------------------------------------------------------------------------
typedef struct _PLAYER
{
int Graph;
float X;
float Y;
float SpeedX;
float SpeedY;
} PLAYER;
//-----------------------------------------------------------------------------
// vg^Cvé
//-----------------------------------------------------------------------------
void PlayerInit(void);
void PlayerUpdate(void);
void PlayerDraw(void);
void ReversePlayerPosition(void);
float GetPlayerX( void );
float GetPlayerY( void );
void SetPlayerX( float x );
void SetPlayerY( float y );
int GetPlayerWidth( void );
int GetPlayerHeight( void );
void SetPlayerSpeedX( float x );
void SetPlayerSpeedY( float y );
//-----------------------------------------------------------------------------
// Ï
//-----------------------------------------------------------------------------
PLAYER Player;
//-----------------------------------------------------------------------------
/**
* vC[Ìú»
* ÀWÌú»AæÌ[hðs
*/
//-----------------------------------------------------------------------------
void PlayerInit(void)
{
// æ[h
Player.Graph = LoadGraph("Resources\\Graphics\\player01.png");
Player.X = 375;
Player.Y = 268;
}
//-----------------------------------------------------------------------------
/**
* vC[ÌXV
* L[üÍAÚ®AeÌ*Ëðs
*/
//-----------------------------------------------------------------------------
void PlayerUpdate(void)
{
// L[üÍp^[
const int KEY_ANGLE[ 16 ] =
{
-1, // 0 0000 ³µ
270, // 1 0001 U
90, // 2 0010 D
-1, // 3 0011 UD
180, // 4 0100 L
225, // 5 0101 UL
135, // 6 0110 DL
180, // 7 0111 UDL
0, // 8 1000 R
315, // 9 1001 UR
45, // 10 1010 DR
0, // 11 1011 UDR
-1, // 12 1100 LR
270, // 13 1101 ULR
90, // 14 1110 DLR
-1 // 15 1111 UDLR
};
// Ú®ûü
unsigned char key_bit = 0;
if( CheckPushKey( KEY_INPUT_W ) )
{
key_bit = key_bit | 1; // 0001
}
if( CheckPushKey( KEY_INPUT_S ) )
{
key_bit = key_bit | 2; // 0010
}
if( CheckPushKey( KEY_INPUT_A ) )
{
key_bit = key_bit | 4; // 0100
}
if( CheckPushKey( KEY_INPUT_D ) )
{
key_bit = key_bit | 8; // 1000
}
// Ú®¬x
int degree = KEY_ANGLE[ key_bit ];
if( degree != -1 )
{
Player.X += (float)(CosDeg( degree ) * Player.SpeedX);
Player.Y += (float)(SinDeg( degree ) * Player.SpeedY);
}
// æÊO»è
if( Player.X < 0 )
{
Player.X = 0;
}
if( Player.Y < 0 )
{
Player.Y = 0;
}
if( Player.X > SCREEN_WIDTH - PLAYER_WIDTH )
{
Player.X = SCREEN_WIDTH - PLAYER_WIDTH;
}
if( Player.Y > SCREEN_HEIGHT - PLAYER_HEIGHT )
{
Player.Y = SCREEN_HEIGHT - PLAYER_HEIGHT;
}
}
//-----------------------------------------------------------------------------
/**
* vC[ÌXV
* Aj[VAæÌ\ðs
*/
//-----------------------------------------------------------------------------
void PlayerDraw(void)
{
DrawRectGraph(
(int)Player.X, (int)Player.Y,
0, 0,
PLAYER_WIDTH, PLAYER_HEIGHT,
Player.Graph, TRUE, FALSE );
}
void ReversePlayerPosition(void)
{
// vC[ÌSðvZ
float x = Player.X + PLAYER_WIDTH/2;
float y = Player.Y + PLAYER_HEIGHT/2;
// æÊÌSÅñ]
float screen_center_x = SCREEN_WIDTH / 2;
float screen_center_y = 348;
x = screen_center_x + (screen_center_x - x);
y = screen_center_y + (screen_center_y - y);
// vC[ÌÊuðÝè
Player.X = x - PLAYER_WIDTH/2;
Player.Y = y - PLAYER_HEIGHT/2;
}
//-----------------------------------------------------------------------------
/**
* vC[ÌXÀWðæ
* @return float : XÀW
*/
//-----------------------------------------------------------------------------
float GetPlayerX( void )
{
return Player.X;
}
//-----------------------------------------------------------------------------
/**
* vC[ÌYÀWðæ
* @return float : YÀW
*/
//-----------------------------------------------------------------------------
float GetPlayerY( void )
{
return Player.Y;
}
//-----------------------------------------------------------------------------
void SetPlayerX( float x )
{
Player.X = x;
}
void SetPlayerY( float y )
{
Player.Y = y;
}
//-----------------------------------------------------------------------------
/**
* vC[Ìðæ
* @return float : \
*/
//-----------------------------------------------------------------------------
int GetPlayerWidth( void )
{
return PLAYER_WIDTH;
}
//-----------------------------------------------------------------------------
/**
* vC[̳ðæ
* @return float : \³
*/
//-----------------------------------------------------------------------------
int GetPlayerHeight( void )
{
return PLAYER_HEIGHT;
}
void SetPlayerSpeedX( float x ) // PROBLEME ICI
{
Player.SpeedX = x;
}
void SetPlayerSpeedY( float y ) // PROBLEME ICI
{
Player.SpeedY = y;
} |
Partager