merge
This commit is contained in:
+12
-1
@@ -69,8 +69,15 @@ void UpdateGame(App *app) {
|
||||
UpdateBirds(&g->birds);
|
||||
UpdateEnemies(&g->enemies, &g->projectiles);
|
||||
UpdateIslands(&g->islands);
|
||||
<<<<<<< HEAD
|
||||
UpdateProjectiles(&g->projectiles, &g->enemies);
|
||||
UpdateSoundtrack(&g->soundtracks[AMBIENT], app->flags.soundtrackOn);
|
||||
=======
|
||||
UpdateProjectiles(&g->projectiles);
|
||||
CheckPlayerCollisions(GetPlayer(), &app->game.enemies);
|
||||
CheckEnemyCollisions(&app->game.enemies);
|
||||
CheckProjectileCollisions(&app->game.projectiles, &app->game.enemies, GetPlayer());
|
||||
>>>>>>> origin/pirate
|
||||
}
|
||||
|
||||
void RenderComponents(App *app) {
|
||||
@@ -92,6 +99,7 @@ void RenderGame(App *app) {
|
||||
BeginMode2D(*camera);
|
||||
RenderComponents(app);
|
||||
EndMode2D();
|
||||
<<<<<<< HEAD
|
||||
DrawTextureRec(
|
||||
g->mouse.cursorTexture,
|
||||
(Rectangle){0, 0, g->mouse.cursorTexture.width,
|
||||
@@ -100,8 +108,11 @@ void RenderGame(App *app) {
|
||||
|
||||
Player *player = GetPlayer();
|
||||
DrawText(TextFormat("Gold: %u", player->gold), 0.0f, 0.0f, 12.0f, YELLOW);
|
||||
=======
|
||||
RenderOverlay(&g->mouse);
|
||||
>>>>>>> origin/pirate
|
||||
EndTextureMode();
|
||||
|
||||
|
||||
BeginDrawing();
|
||||
ClearBackground(BLACK);
|
||||
for (int i = 0; i < SHADER_COUNT; i++) {
|
||||
|
||||
@@ -0,0 +1,102 @@
|
||||
#include "app.h"
|
||||
|
||||
float playerCollisionRadius = 8.0f;
|
||||
float enemiesCollisionRadius = 8.0f;
|
||||
float projectilesCollisionRadius = 1.0f;
|
||||
|
||||
void CheckPlayerCollisions(Player *player, Enemies *enemies) {
|
||||
for (int i = 0; i < enemies->count; i++) {
|
||||
|
||||
Vector2 playerPos = player->physics.position;
|
||||
Vector2 enemiesPos = enemies->physics[i].position;
|
||||
|
||||
float minDist = playerCollisionRadius + enemiesCollisionRadius;
|
||||
|
||||
if (CheckCollisionCircles(playerPos, playerCollisionRadius, enemiesPos,
|
||||
enemiesCollisionRadius)) {
|
||||
|
||||
player->health -= 1;
|
||||
|
||||
float dist = GetDistanceBetweenTwoVectors(playerPos, enemiesPos);
|
||||
float overlap = minDist - dist;
|
||||
|
||||
if (dist > 0.0f) {
|
||||
Vector2 collisionVector = GetDirectionBetweenTwoVectors(
|
||||
enemies->physics[i].position, player->physics.position);
|
||||
player->physics.position.x += collisionVector.x * overlap;
|
||||
player->physics.position.y += collisionVector.y * overlap;
|
||||
Vector2 forward = RotationToVector2(player->rotation - 90.0f);
|
||||
float side = Cross2D(forward, collisionVector);
|
||||
player->rotation += side * 120.0f * GetFrameTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckEnemyCollisions(Enemies *enemies) {
|
||||
for (int a = 0; a < enemies->count; a++) {
|
||||
for (int b = a + 1; b < enemies->count; b++) {
|
||||
|
||||
Vector2 posA = enemies->physics[a].position;
|
||||
Vector2 posB = enemies->physics[b].position;
|
||||
|
||||
float minDist = enemiesCollisionRadius * 2;
|
||||
|
||||
if (CheckCollisionCircles(posA, enemiesCollisionRadius, posB,
|
||||
enemiesCollisionRadius)) {
|
||||
|
||||
Vector2 collisionVectorA = GetDirectionBetweenTwoVectors(posB, posA);
|
||||
Vector2 collisionVectorB = GetDirectionBetweenTwoVectors(posA, posB);
|
||||
float dist = GetDistanceBetweenTwoVectors(posA, posB);
|
||||
float overlap = minDist - dist;
|
||||
|
||||
if (dist > 0.0f) {
|
||||
enemies->physics[a].position.x += collisionVectorA.x * overlap * 0.5f;
|
||||
enemies->physics[a].position.y += collisionVectorA.y * overlap * 0.5f;
|
||||
|
||||
enemies->physics[b].position.x += collisionVectorB.x * overlap * 0.5f;
|
||||
enemies->physics[b].position.y += collisionVectorB.y * overlap * 0.5f;
|
||||
|
||||
Vector2 forwardA =
|
||||
RotationToVector2(enemies->sprite[a].rotation - 90.0f);
|
||||
Vector2 forwardB =
|
||||
RotationToVector2(enemies->sprite[b].rotation - 90.0f);
|
||||
float sideA = Cross2D(forwardA, collisionVectorA);
|
||||
float sideB = Cross2D(forwardB, collisionVectorB);
|
||||
enemies->sprite[a].rotation += sideA * 120.0f * GetFrameTime();
|
||||
enemies->sprite[b].rotation += sideB * 120.0f * GetFrameTime();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void CheckProjectileCollisions(Projectiles *projectiles, Enemies *enemies,
|
||||
Player *player) {
|
||||
for (int i = 0; i < projectiles->count; i++) {
|
||||
if (!projectiles->active[i])
|
||||
continue;
|
||||
Vector2 projectilePos = projectiles->physics[i].position;
|
||||
for (int j = 0; j < enemies->count; j++) {
|
||||
Vector2 enemyPos = enemies->physics[j].position;
|
||||
|
||||
if (CheckCollisionCircles(projectilePos, projectilesCollisionRadius,
|
||||
enemyPos, enemiesCollisionRadius)) {
|
||||
player->gold += 20;
|
||||
Rectangle cameraRec = GetCameraRectangle();
|
||||
enemies->physics[j].position =
|
||||
GetPositionOutsideRectangle(cameraRec, 100, 1000);
|
||||
}
|
||||
}
|
||||
|
||||
if (!projectiles->active[i])
|
||||
continue;
|
||||
|
||||
Vector2 playerPos = player->physics.position;
|
||||
if (CheckCollisionCircles(projectilePos, projectilesCollisionRadius,
|
||||
playerPos, playerCollisionRadius)) {
|
||||
|
||||
player->health -= 20;
|
||||
}
|
||||
}
|
||||
}
|
||||
+82
-28
@@ -1,47 +1,62 @@
|
||||
#include "app.h"
|
||||
|
||||
const TextureAsset enemiesTextureAssets[ENEMIES_TEX_COUNT] = {
|
||||
{"assets/ship_start.png", 16.0f, 16.0f, 90.0f}};
|
||||
{"assets/ship_start.png", 16.0f, 16.0f, 90.0f}
|
||||
};
|
||||
|
||||
Enemies CreateEnemies(void) {
|
||||
Enemies enemies = {.count = MAX_ENEMIES};
|
||||
TextureAsset textureAsset = enemiesTextureAssets[BOAT];
|
||||
Texture2D texture = LoadTexture(textureAsset.path);
|
||||
float frameWidth = textureAsset.frameWidth;
|
||||
float rotation = textureAsset.rotation;
|
||||
Enemies CreateEnemies(void){
|
||||
Enemies enemies = {.count = MAX_ENEMIES};
|
||||
TextureAsset textureAsset = enemiesTextureAssets[BOAT];
|
||||
Texture2D texture = LoadTexture(textureAsset.path);
|
||||
float frameWidth = textureAsset.frameWidth;
|
||||
float rotation = textureAsset.rotation;
|
||||
|
||||
for (int i = 0; i < enemies.count; i++) {
|
||||
enemies.sprite[i] = (Sprite){
|
||||
.texture = texture,
|
||||
.frameSize = {frameWidth, frameWidth},
|
||||
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||
.destRec = {GetScreenWidth() / 2, 0.0f, frameWidth, frameWidth},
|
||||
.origin = {frameWidth / 2, frameWidth / 2},
|
||||
.rotation = rotation,
|
||||
.color = WHITE};
|
||||
for (int i = 0; i < enemies.count; i++)
|
||||
{
|
||||
enemies.sprite[i] = (Sprite){
|
||||
.texture = texture,
|
||||
.frameSize = {frameWidth, frameWidth},
|
||||
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||
.destRec = {GetScreenWidth()/2, 0.0f, frameWidth, frameWidth},
|
||||
.origin = {frameWidth / 2, frameWidth / 2},
|
||||
.rotation = rotation,
|
||||
.color = WHITE
|
||||
};
|
||||
|
||||
enemies.animation[i] = (Animation){.state = 1,
|
||||
.currentFrame = 0,
|
||||
.maxFrame = 2,
|
||||
.framesCounter = 0,
|
||||
.framesSpeed = 2.0f,
|
||||
.animTimer = 0.0f};
|
||||
enemies.animation[i] = (Animation){
|
||||
.state = 1,
|
||||
.currentFrame = 0,
|
||||
.maxFrame = 2,
|
||||
.framesCounter = 0,
|
||||
.framesSpeed = 2.0f,
|
||||
.animTimer = 0.0f
|
||||
};
|
||||
|
||||
Rectangle cameraRec = GetCameraRectangle();
|
||||
Rectangle cameraRec = GetCameraRectangle();
|
||||
|
||||
enemies.physics[i] =
|
||||
(Physics){.position = GetPositionOutsideRectangle(cameraRec, 100, 1000),
|
||||
.direction = (Vector2){0.0f, 0.0f},
|
||||
.speed = 5.0f};
|
||||
enemies.physics[i] = (Physics){
|
||||
.position = GetPositionOutsideRectangle(cameraRec, 100, 1000),
|
||||
.direction = (Vector2){0.0f, 0.0f},
|
||||
.speed = 5.0f,
|
||||
.weight = 5.0f
|
||||
};
|
||||
|
||||
<<<<<<< HEAD
|
||||
enemies.arrived[i] = true;
|
||||
enemies.destPos[i] = (Vector2){0.0f, 0.0f};
|
||||
enemies.alive[i] = true;
|
||||
}
|
||||
=======
|
||||
enemies.arrived[i] = true;
|
||||
enemies.destPos[i] = (Vector2){0.0f, 0.0f};
|
||||
>>>>>>> origin/pirate
|
||||
|
||||
return enemies;
|
||||
}
|
||||
|
||||
return enemies;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
void UpdateEnemies(Enemies *enemies, Projectiles *projectiles) {
|
||||
Camera2D *camera = GetCamera();
|
||||
Rectangle cameraRec = GetCameraRectangle();
|
||||
@@ -91,4 +106,43 @@ void RenderEnemies(Enemies *enemies) {
|
||||
RenderSprite(&enemies->sprite[i]);
|
||||
}
|
||||
}
|
||||
=======
|
||||
void UpdateEnemies(Enemies *enemies){
|
||||
Camera2D *camera = GetCamera();
|
||||
Rectangle cameraRec = GetCameraRectangle();
|
||||
|
||||
for (int i = 0; i < enemies->count; i++)
|
||||
{
|
||||
if(enemies->arrived[i])
|
||||
{
|
||||
enemies->destPos[i] = GetPositionOutsideRectangle(cameraRec, 100, 1000);
|
||||
enemies->arrived[i] = false;
|
||||
}
|
||||
if(CheckCollisionPointCircle(enemies->physics[i].position, enemies->destPos[i], 10.0F))
|
||||
{
|
||||
enemies->arrived[i] = true;
|
||||
}
|
||||
if(GetDistanceBetweenTwoVectors(enemies->physics[i].position, camera->target) > 1000){
|
||||
enemies->physics[i].position = GetPositionOutsideRectangle(cameraRec, 100, 1000);
|
||||
}
|
||||
Vector2 dir = GetDirectionBetweenTwoVectors(enemies->physics[i].position, enemies->destPos[i]);
|
||||
UpdatePhysics(&enemies->physics[i], dir);
|
||||
UpdateSpriteDestRec(&enemies->sprite[i], &enemies->physics[i].position);
|
||||
float rotation = Vector2ToRotation(dir);
|
||||
UpdateSpriteRotation(&enemies->sprite[i], rotation + 90.0f);
|
||||
UpdateAnimation(&enemies->animation[i], GetFrameTime());
|
||||
UpdateSpriteSourceRec(&enemies->sprite[i], &(Vector2){enemies->sprite[i].frameSize.x * enemies->animation[i].currentFrame, enemies->sprite[i].frameSize.y});
|
||||
}
|
||||
}
|
||||
|
||||
void RenderEnemies(Enemies *enemies){
|
||||
|
||||
for (int i = 0; i < enemies->count; i++)
|
||||
{
|
||||
RenderSprite(&enemies->sprite[i]);
|
||||
}
|
||||
|
||||
>>>>>>> origin/pirate
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
#include "app.h"
|
||||
#include "raylib.h"
|
||||
#include <limits.h>
|
||||
|
||||
void RenderOverlay(Mouse *mouse) {
|
||||
|
||||
// Health
|
||||
Player *player = GetPlayer();
|
||||
const char *text = TextFormat("Health: %i\n"
|
||||
"Gold: %i\n",
|
||||
player->health, player->gold);
|
||||
DrawText(text, 0, 0, 25, WHITE);
|
||||
|
||||
// Mouse
|
||||
Rectangle mouseRectangle = (Rectangle){0, 0, mouse->cursorTexture.width,
|
||||
mouse->cursorTexture.height};
|
||||
DrawTextureRec(mouse->cursorTexture, mouseRectangle, mouse->screenPosition,
|
||||
WHITE);
|
||||
}
|
||||
+98
-48
@@ -1,4 +1,5 @@
|
||||
#include "app.h"
|
||||
#include "engine.h"
|
||||
|
||||
typedef enum {
|
||||
FLAPPING,
|
||||
@@ -10,30 +11,27 @@ const SoundAsset playerSoundAssets[SOUND_COUNT] = {
|
||||
};
|
||||
|
||||
const TextureAsset playerTextureAssets[PLAYER_TEX_COUNT] = {
|
||||
{"assets/ship_start.png", 16.0f, 16.0f, 0.0f}
|
||||
};
|
||||
{"assets/ship_start.png", 16.0f, 16.0f, 0.0f}};
|
||||
|
||||
float playerSpeeds[SPEED_COUNT] = {
|
||||
0.0f,
|
||||
5.0f,
|
||||
10.0f
|
||||
};
|
||||
float playerSpeeds[SPEED_COUNT] = {0.0f, 5.0f, 10.0f};
|
||||
|
||||
Config config;
|
||||
|
||||
playerSpeedID GetPlayerSpeedID(float speed) {
|
||||
for (int i = 0; i < SPEED_COUNT; i++) {
|
||||
if (playerSpeeds[i] == speed) {
|
||||
return (playerSpeedID)i;
|
||||
}
|
||||
for (int i = 0; i < SPEED_COUNT; i++) {
|
||||
if (playerSpeeds[i] == speed) {
|
||||
return (playerSpeedID)i;
|
||||
}
|
||||
return ANCHOR;
|
||||
}
|
||||
return ANCHOR;
|
||||
}
|
||||
|
||||
Player* GetPlayer(void)
|
||||
{
|
||||
static Player player;
|
||||
return &player;
|
||||
Player *GetPlayer(void) {
|
||||
static Player player;
|
||||
return &player;
|
||||
}
|
||||
|
||||
<<<<<<< HEAD
|
||||
void CreatePlayer(void)
|
||||
{
|
||||
TextureAsset startShipAsset = playerTextureAssets[START_SHIP];
|
||||
@@ -51,16 +49,17 @@ void CreatePlayer(void)
|
||||
.rotation = rotation,
|
||||
.color = WHITE
|
||||
};
|
||||
=======
|
||||
void CreatePlayer(void) {
|
||||
|
||||
Animation playerAnimation = {
|
||||
.state = 1,
|
||||
.currentFrame = 0,
|
||||
.maxFrame = 3,
|
||||
.framesCounter = 0,
|
||||
.framesSpeed = 0.0f,
|
||||
.animTimer = 0.0f
|
||||
};
|
||||
InitConfig(&config, "config/player.ini");
|
||||
int PLAYER_HEALTH_MAX = GetConfigInt(&config, "HEALTH_MAX");
|
||||
int START_GOLD = GetConfigInt(&config, "START_GOLD");
|
||||
>>>>>>> origin/pirate
|
||||
|
||||
TextureAsset startShipAsset = playerTextureAssets[START_SHIP];
|
||||
|
||||
<<<<<<< HEAD
|
||||
Physics playerPhysics = {
|
||||
.position = (Vector2){(float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX), (float)LoadStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY)},
|
||||
.direction = (Vector2){0.0f, 0.0f},
|
||||
@@ -95,35 +94,83 @@ void UpdatePlayer(void)
|
||||
}
|
||||
}
|
||||
}
|
||||
=======
|
||||
Texture2D texture = LoadTexture(startShipAsset.path);
|
||||
float frameWidth = startShipAsset.frameWidth;
|
||||
float rotation = startShipAsset.rotation;
|
||||
|
||||
if(IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)){
|
||||
if(player->physics.speed > playerSpeeds[ANCHOR]){
|
||||
if(player->physics.speed > playerSpeeds[SLOW_AHEAD]){
|
||||
player->physics.speed = playerSpeeds[SLOW_AHEAD];
|
||||
}
|
||||
else {
|
||||
player->physics.speed = playerSpeeds[ANCHOR];
|
||||
Sprite playerSprite = {.texture = texture,
|
||||
.frameSize = {frameWidth, frameWidth},
|
||||
.sourceRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||
.destRec = {0.0f, 0.0f, frameWidth, frameWidth},
|
||||
.origin = {frameWidth / 2, frameWidth / 2},
|
||||
.rotation = rotation,
|
||||
.color = WHITE};
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Animation playerAnimation = {.state = 1,
|
||||
.currentFrame = 0,
|
||||
.maxFrame = 3,
|
||||
.framesCounter = 0,
|
||||
.framesSpeed = 0.0f,
|
||||
.animTimer = 0.0f};
|
||||
|
||||
player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed);
|
||||
Physics playerPhysics = {.position = (Vector2){0.0f, 0.0f},
|
||||
.direction = (Vector2){0.0f, 0.0f},
|
||||
.speed = playerSpeeds[ANCHOR],
|
||||
.weight = 10.0f};
|
||||
|
||||
Player *player = GetPlayer();
|
||||
*player = (Player){.sprite = playerSprite,
|
||||
.animation = playerAnimation,
|
||||
.physics = playerPhysics,
|
||||
.rotation = rotation,
|
||||
.health = PLAYER_HEALTH_MAX,
|
||||
.gold = START_GOLD};
|
||||
}
|
||||
|
||||
float rotationSpeed = 50.0f;
|
||||
void UpdatePlayer(void) {
|
||||
Player *player = GetPlayer();
|
||||
if (IsKeyPressed(KEY_W) || IsKeyPressed(KEY_UP)) {
|
||||
if (player->physics.speed < playerSpeeds[FAST_AHEAD]) {
|
||||
if (player->physics.speed < playerSpeeds[SLOW_AHEAD]) {
|
||||
player->physics.speed = playerSpeeds[SLOW_AHEAD];
|
||||
} else {
|
||||
player->physics.speed = playerSpeeds[FAST_AHEAD];
|
||||
}
|
||||
}
|
||||
}
|
||||
>>>>>>> origin/pirate
|
||||
|
||||
if (player->physics.speed > playerSpeeds[ANCHOR]){
|
||||
if (IsKeyPressed(KEY_S) || IsKeyPressed(KEY_DOWN)) {
|
||||
if (player->physics.speed > playerSpeeds[ANCHOR]) {
|
||||
if (player->physics.speed > playerSpeeds[SLOW_AHEAD]) {
|
||||
player->physics.speed = playerSpeeds[SLOW_AHEAD];
|
||||
} else {
|
||||
player->physics.speed = playerSpeeds[ANCHOR];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) {
|
||||
player->rotation -= rotationSpeed * GetFrameTime();
|
||||
}
|
||||
player->sprite.sourceRec.x = 16.0f * GetPlayerSpeedID(player->physics.speed);
|
||||
|
||||
if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) {
|
||||
player->rotation += rotationSpeed * GetFrameTime();
|
||||
}
|
||||
}
|
||||
float rotationSpeed = 50.0f;
|
||||
|
||||
if (player->physics.speed > playerSpeeds[ANCHOR]) {
|
||||
|
||||
if (IsKeyDown(KEY_A) || IsKeyDown(KEY_LEFT)) {
|
||||
player->rotation -= rotationSpeed * GetFrameTime();
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_D) || IsKeyDown(KEY_RIGHT)) {
|
||||
player->rotation += rotationSpeed * GetFrameTime();
|
||||
}
|
||||
}
|
||||
|
||||
player->sprite.rotation = player->rotation;
|
||||
|
||||
Vector2 dir = RotationToVector2(player->rotation - 90.0f);
|
||||
|
||||
<<<<<<< HEAD
|
||||
player->sprite.rotation = player->rotation;
|
||||
Vector2 dir = RotationToVector2(player->rotation - 90.0f);
|
||||
UpdatePhysics(&player->physics, dir);
|
||||
@@ -131,10 +178,13 @@ void UpdatePlayer(void)
|
||||
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSX, (int)player->physics.position.x);
|
||||
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_POSY, (int)player->physics.position.y);
|
||||
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_ROTATION, (int)player->rotation);
|
||||
=======
|
||||
UpdatePhysics(&player->physics, dir);
|
||||
UpdateSpriteDestRec(&player->sprite, &player->physics.position);
|
||||
>>>>>>> origin/pirate
|
||||
}
|
||||
|
||||
void RenderPlayer(void){
|
||||
Player* player = GetPlayer();
|
||||
RenderSprite(&player->sprite);
|
||||
void RenderPlayer(void) {
|
||||
Player *player = GetPlayer();
|
||||
RenderSprite(&player->sprite);
|
||||
}
|
||||
|
||||
|
||||
+16
-18
@@ -2,16 +2,10 @@
|
||||
#include <raylib.h>
|
||||
#include <raymath.h>
|
||||
|
||||
typedef enum {
|
||||
CANNONBALL_SHOOTING,
|
||||
CANNONBALL_IMPACT,
|
||||
SOUND_COUNT
|
||||
} SoundID;
|
||||
typedef enum { CANNONBALL_SHOOTING, CANNONBALL_IMPACT, SOUND_COUNT } SoundID;
|
||||
|
||||
const SoundAsset soundAssets[SOUND_COUNT] = {
|
||||
{"assets/cannonball_shooting.mp3"},
|
||||
{"assets/cannonball_impact.mp3"}
|
||||
};
|
||||
const SoundAsset soundAssets[SOUND_COUNT] = {{"assets/cannonball_shooting.mp3"},
|
||||
{"assets/cannonball_impact.mp3"}};
|
||||
|
||||
Projectiles CreateProjectiles(void) {
|
||||
Projectiles projectiles = {.count = MAX_PROJECTILES};
|
||||
@@ -23,7 +17,8 @@ Projectiles CreateProjectiles(void) {
|
||||
projectiles.radius[i] = 1.0f;
|
||||
projectiles.active[i] = false;
|
||||
projectiles.color[i] = GRAY;
|
||||
projectiles.soundShooting[i] = LoadSound(soundAssets[CANNONBALL_SHOOTING].path);
|
||||
projectiles.soundShooting[i] =
|
||||
LoadSound(soundAssets[CANNONBALL_SHOOTING].path);
|
||||
projectiles.soundImpact[i] = LoadSound(soundAssets[CANNONBALL_IMPACT].path);
|
||||
}
|
||||
|
||||
@@ -52,7 +47,7 @@ void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies) {
|
||||
}
|
||||
|
||||
if (IsKeyDown(KEY_E) && (currentTime - lastShotTime >= reloadTime)) {
|
||||
for (int i = 0; i < projectiles->count; i++){
|
||||
for (int i = 0; i < projectiles->count; i++) {
|
||||
if (!projectiles->active[i]) {
|
||||
projectiles->active[i] = true;
|
||||
Player *player = GetPlayer();
|
||||
@@ -68,26 +63,29 @@ void UpdateProjectiles(Projectiles *projectiles, Enemies *enemies) {
|
||||
|
||||
for (int i = 0; i < projectiles->count; i++) {
|
||||
|
||||
if (!projectiles->active[i]) continue;
|
||||
if (!projectiles->active[i])
|
||||
continue;
|
||||
|
||||
for (int j = 0; j < enemies->count; j++){
|
||||
if (CheckCollisionCircleRec(projectiles->physics[i].position, projectiles->radius[i], enemies->sprite[j].destRec)){
|
||||
for (int j = 0; j < enemies->count; j++) {
|
||||
if (CheckCollisionCircleRec(projectiles->physics[i].position,
|
||||
projectiles->radius[i],
|
||||
enemies->sprite[j].destRec)) {
|
||||
PlaySound(projectiles->soundImpact[i]);
|
||||
Player *player = GetPlayer();
|
||||
player->gold += 1;
|
||||
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_GOLD, player->gold);
|
||||
SaveStorageValue(STORAGE_DATA_FILE, STORAGE_POSITION_GOLD,
|
||||
player->gold);
|
||||
projectiles->active[i] = false;
|
||||
}
|
||||
}
|
||||
|
||||
UpdatePhysics(&projectiles->physics[i],
|
||||
projectiles->physics[i].direction);
|
||||
UpdatePhysics(&projectiles->physics[i], projectiles->physics[i].direction);
|
||||
}
|
||||
}
|
||||
|
||||
void RenderProjectiles(Projectiles *projectiles) {
|
||||
for (int i = 0; i < projectiles->count; i++) {
|
||||
if (projectiles->active[i]) {
|
||||
if (projectiles->active[i] == true) {
|
||||
DrawCircle(projectiles->physics[i].position.x,
|
||||
projectiles->physics[i].position.y, projectiles->radius[i],
|
||||
projectiles->color[i]);
|
||||
|
||||
+15
-16
@@ -1,27 +1,26 @@
|
||||
#include "engine.h"
|
||||
|
||||
bool IsVectorZero(Vector2 v) {
|
||||
float epsilon = 0.01f;
|
||||
return (fabs(v.x) < epsilon && fabs(v.y) < epsilon);
|
||||
float epsilon = 0.01f;
|
||||
return (fabs(v.x) < epsilon && fabs(v.y) < epsilon);
|
||||
}
|
||||
|
||||
Vector2 GetRandomVector(const Rectangle bounds) {
|
||||
return (Vector2){
|
||||
bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width,
|
||||
bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height
|
||||
};
|
||||
return (Vector2){
|
||||
bounds.x + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.width,
|
||||
bounds.y + (float)GetRandomValue(0, 10000) / 10000.0f * bounds.height};
|
||||
}
|
||||
|
||||
Vector2 RotationToVector2(float rotation)
|
||||
{
|
||||
float rad = rotation * (PI / 180.0f);
|
||||
Vector2 vec = { cosf(rad), sinf(rad) };
|
||||
return vec;
|
||||
Vector2 RotationToVector2(float rotation) {
|
||||
float rad = rotation * (PI / 180.0f);
|
||||
Vector2 vec = {cosf(rad), sinf(rad)};
|
||||
return vec;
|
||||
}
|
||||
|
||||
float Vector2ToRotation(Vector2 vec)
|
||||
{
|
||||
float rad = atan2f(vec.y, vec.x);
|
||||
float deg = rad * (180.0f / PI);
|
||||
return deg;
|
||||
float Vector2ToRotation(Vector2 vec) {
|
||||
float rad = atan2f(vec.y, vec.x);
|
||||
float deg = rad * (180.0f / PI);
|
||||
return deg;
|
||||
}
|
||||
|
||||
float Cross2D(Vector2 a, Vector2 b) { return a.x * b.y - a.y * b.x; }
|
||||
|
||||
Reference in New Issue
Block a user