Add rocket

This commit is contained in:
Miloslav Číž 2019-10-14 13:31:13 +02:00
parent c517fc5dc8
commit 1640902e21
3 changed files with 86 additions and 13 deletions

View File

@ -632,6 +632,51 @@ uint8_t SFG_weaponImages[][SFG_TEXTURE_SIZE * SFG_TEXTURE_SIZE] =
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,1,1,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175
},
{ // 1, rocket launcher
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,0,0,0,0,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,0,0,0,0,5,4,2,2,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,0,6,6,6,5,4,2,142,141,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,0,4,4,4,4,4,2,142,141,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,0,3,
3,3,3,3,3,2,1,175,175,175,175,175,175,175,175,175,175,175,0,0,0,0,175,175,175,
175,175,175,175,0,0,1,1,1,1,1,1,1,1,175,175,175,175,175,175,175,175,0,0,0,2,2,2,
2,0,0,175,0,0,0,0,118,118,118,116,1,1,114,114,114,1,175,175,175,175,175,175,0,0,
5,5,2,2,2,2,50,50,2,0,117,117,118,118,117,116,116,115,114,1,114,114,36,36,175,
175,175,175,175,0,5,5,2,2,2,2,2,115,116,116,116,117,116,116,116,115,115,115,115,
116,115,6,116,116,117,117,175,175,175,175,0,20,5,2,2,2,2,115,115,115,115,115,
115,115,115,116,116,116,116,116,117,116,6,117,117,117,117,117,175,175,175,0,20,
23,2,2,2,2,115,116,116,117,116,116,116,116,116,116,117,117,117,37,37,36,6,37,37,
38,38,38,175,175,175,0,23,23,2,2,2,117,117,117,117,117,117,117,117,117,117,37,
37,38,38,5,36,6,38,39,38,38,39,38,175,175,175,0,7,2,2,2,115,117,37,37,37,37,37,
37,37,37,37,6,6,6,6,6,4,7,6,6,6,6,6,6,175,175,0,23,7,2,2,2,117,38,45,45,5,5,5,6,
6,6,6,6,6,6,6,39,4,7,6,39,39,39,39,39,175,175,0,7,7,2,2,2,117,39,39,39,39,7,7,7,
7,7,7,7,7,7,7,7,5,7,7,7,7,7,7,25,175,175,0,7,7,2,2,2,117,39,39,7,7,7,7,7,7,7,7,
7,7,7,7,7,5,7,7,7,7,7,25,100,175,175,0,23,7,2,2,2,117,37,37,37,37,37,38,38,38,
38,38,38,38,38,39,39,37,7,39,39,39,25,109,30,175,175,0,5,7,2,2,2,35,35,36,36,36,
36,36,36,36,117,117,117,118,118,37,37,36,6,38,38,38,25,30,21,175,175,0,5,23,2,2,
2,115,115,115,115,115,115,115,116,116,116,116,116,116,117,117,36,116,6,36,37,37,
25,109,109,175,175,175,0,23,2,2,2,2,115,115,115,115,115,115,115,115,115,115,115,
115,115,116,116,115,6,116,116,36,25,109,21,175,175,175,0,5,20,2,2,2,33,114,114,
114,115,115,115,115,115,115,115,115,115,115,115,115,6,115,115,115,25,109,21,175,
175,175,0,5,5,2,2,2,2,33,33,114,114,114,114,114,114,114,114,115,115,115,115,115,
115,6,115,115,25,109,21,175,175,175,175,0,5,5,2,2,2,2,33,1,1,33,33,33,33,33,114,
114,114,114,114,114,115,6,115,115,25,30,21,175,175,175,175,175,0,5,5,2,2,2,2,2,
41,1,40,41,34,34,41,33,33,33,33,114,114,115,6,114,25,30,21,175,175,175,175,175,
175,0,0,5,5,2,2,2,2,2,2,2,0,1,41,34,49,49,33,33,33,115,6,114,25,109,21,175,175,
175,175,175,175,175,175,0,0,0,2,2,2,2,0,0,175,0,0,0,0,49,33,41,41,34,41,6,25,30,
21,175,175,175,175,175,175,175,175,175,175,175,0,0,0,0,175,175,175,175,175,175,
175,0,0,0,0,57,42,116,25,109,21,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,0,0,0,25,21,21,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,0,100,21,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,0,
100,100,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,0,107,175,175,175,175,175,175,
175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,175,
175,175,175,175,175,0
}
};

Binary file not shown.

After

Width:  |  Height:  |  Size: 960 B

54
main.c
View File

@ -95,7 +95,7 @@ void SFG_init();
#define RCL_TEXTURE_VERTICAL_STRETCH 0
#define RCL_CAMERA_COLL_HEIGHT_BELOW 800
#define RCL_CAMERA_COLL_HEIGHT_ABOVE 100
#define RCL_CAMERA_COLL_HEIGHT_ABOVE 150
#include "raycastlib.h"
@ -216,9 +216,9 @@ struct
for determining whether player is in the
air. */
uint16_t headBobFrame;
uint8_t weapon; //< currently selected weapon
} SFG_player;
#if SFG_RESOLUTION_SCALEDOWN == 1
#define SFG_setGamePixel SFG_setPixel
#else
@ -274,6 +274,8 @@ void SFG_initPlayer()
SFG_player.previousVerticalSpeed = 0;
SFG_player.headBobFrame = 0;
SFG_player.weapon = 0;
}
RCL_RayConstraints SFG_rayConstraints;
@ -863,6 +865,12 @@ void SFG_init()
SFG_lastFrameTimeMs = SFG_getTimeMs();
}
void SFG_playerRotateWeapon(uint8_t next)
{
SFG_player.weapon = (SFG_player.weapon + (next * 2 - 1));
SFG_player.weapon %= 2;
}
/**
Performs one game step (logic, physics), happening SFG_MS_PER_FRAME after
previous frame.
@ -903,22 +911,42 @@ void SFG_gameStep()
shearing = 1;
}
if (SFG_keyPressed(SFG_KEY_LEFT))
strafe = -1;
else if (SFG_keyPressed(SFG_KEY_RIGHT))
strafe = 1;
if (!SFG_keyPressed(SFG_KEY_C))
{
if (SFG_keyPressed(SFG_KEY_LEFT))
strafe = -1;
else if (SFG_keyPressed(SFG_KEY_RIGHT))
strafe = 1;
}
else
{
if (SFG_keyPressed(SFG_KEY_LEFT))
SFG_playerRotateWeapon(0);
else if (SFG_keyPressed(SFG_KEY_RIGHT))
SFG_playerRotateWeapon(1);
}
}
else
{
if (SFG_keyPressed(SFG_KEY_LEFT))
if (!SFG_keyPressed(SFG_KEY_C))
{
SFG_player.camera.direction -= SFG_PLAYER_TURN_UNITS_PER_FRAME;
recomputeDirection = 1;
if (SFG_keyPressed(SFG_KEY_LEFT))
{
SFG_player.camera.direction -= SFG_PLAYER_TURN_UNITS_PER_FRAME;
recomputeDirection = 1;
}
else if (SFG_keyPressed(SFG_KEY_RIGHT))
{
SFG_player.camera.direction += SFG_PLAYER_TURN_UNITS_PER_FRAME;
recomputeDirection = 1;
}
}
else if (SFG_keyPressed(SFG_KEY_RIGHT))
else
{
SFG_player.camera.direction += SFG_PLAYER_TURN_UNITS_PER_FRAME;
recomputeDirection = 1;
if (SFG_keyPressed(SFG_KEY_LEFT))
SFG_playerRotateWeapon(0);
else if (SFG_keyPressed(SFG_KEY_RIGHT))
SFG_playerRotateWeapon(1);
}
if (recomputeDirection)
@ -1375,7 +1403,7 @@ SFG_drawText("ammo",
SFG_GAME_RESOLUTION_X - 10 - 4 * (SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM + 1)
,SFG_GAME_RESOLUTION_Y - 10 - SFG_FONT_CHARACTER_SIZE * SFG_FONT_SIZE_MEDIUM,SFG_FONT_SIZE_MEDIUM,7);
SFG_blitImage(SFG_weaponImages[0],
SFG_blitImage(SFG_weaponImages[SFG_player.weapon],
SFG_WEAPON_IMAGE_POSITION_X,
SFG_WEAPON_IMAGE_POSITION_Y + weaponBobOffset,
SFG_WEAPON_IMAGE_SCALE);