Merge remote-tracking branch 'refs/remotes/origin/pirate' into pirate
This commit is contained in:
@@ -35,7 +35,7 @@ ifeq ($(OS), Windows_NT)
|
||||
else
|
||||
SRC = $(wildcard src/*.c)
|
||||
TARGET = bin/osx/game
|
||||
RAYLIB_FLAGS = $(shell pkg-config --libs --cflags raylib)
|
||||
RAYLIB_FLAGS = $(shell pkg-config --libs --cflags raylib) -lm
|
||||
endif
|
||||
|
||||
$(shell mkdir -p bin/osx bin/win)
|
||||
|
||||
+30
-5
@@ -52,11 +52,6 @@ typedef enum {
|
||||
SPEED_COUNT
|
||||
} playerSpeedID;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FLYING,
|
||||
BIRDS_TEX_COUNT
|
||||
} birdsTextureID;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
@@ -152,7 +147,32 @@ typedef struct
|
||||
float rotation;
|
||||
} Player;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
BOAT,
|
||||
ENEMIES_TEX_COUNT
|
||||
} enemiesTextureID;
|
||||
|
||||
#define MAX_ENEMIES 100
|
||||
|
||||
typedef struct
|
||||
{
|
||||
int count;
|
||||
Sprite sprite[MAX_ENEMIES];
|
||||
Animation animation[MAX_ENEMIES];
|
||||
Physics physics[MAX_ENEMIES];
|
||||
bool arrived[MAX_ENEMIES];
|
||||
Vector2 destPos[MAX_ENEMIES];
|
||||
} Enemies;
|
||||
|
||||
typedef enum
|
||||
{
|
||||
FLYING,
|
||||
BIRDS_TEX_COUNT
|
||||
} birdsTextureID;
|
||||
|
||||
#define MAX_BIRDS 100
|
||||
|
||||
typedef struct {
|
||||
int count;
|
||||
Sprite sprite[MAX_BIRDS];
|
||||
@@ -176,6 +196,7 @@ typedef struct
|
||||
RenderTexture2D target;
|
||||
Floor floor;
|
||||
Birds birds;
|
||||
Enemies enemies;
|
||||
Islands islands;
|
||||
Mouse mouse;
|
||||
Image image;
|
||||
@@ -245,6 +266,10 @@ void CreatePlayer(void);
|
||||
void UpdatePlayer(void);
|
||||
void RenderPlayer(void);
|
||||
|
||||
Enemies CreateEnemies(void);
|
||||
void UpdateEnemies(Enemies *enemies);
|
||||
void RenderEnemies(Enemies *enemies);
|
||||
|
||||
Birds CreateBirds(void);
|
||||
void UpdateBirds(Birds *birds);
|
||||
void RenderBirds(Birds *birds);
|
||||
|
||||
@@ -37,6 +37,7 @@ void InitGame(App *app)
|
||||
Player* player = GetPlayer();
|
||||
CreateCamera(player->physics.position, 10.0f);
|
||||
g->birds = CreateBirds();
|
||||
g->enemies = CreateEnemies();
|
||||
g->islands = CreateIslands();
|
||||
g->floor = CreateFloor();
|
||||
|
||||
@@ -78,6 +79,7 @@ void UpdateGame(App *app)
|
||||
UpdateFloor(&g->floor);
|
||||
UpdatePlayer();
|
||||
UpdateBirds(&g->birds);
|
||||
UpdateEnemies(&g->enemies);
|
||||
UpdateIslands(&g->islands);
|
||||
}
|
||||
|
||||
@@ -86,6 +88,7 @@ void RenderComponents(App *app)
|
||||
GameState *g = &app->game;
|
||||
RenderFloor(&g->floor);
|
||||
RenderPlayer();
|
||||
RenderEnemies(&g->enemies);
|
||||
RenderBirds(&g->birds);
|
||||
RenderIslands(&g->islands);
|
||||
}
|
||||
|
||||
@@ -70,8 +70,6 @@ void UpdateBirds(Birds *birds){
|
||||
}
|
||||
Vector2 dir = GetDirectionBetweenTwoVectors(birds->physics[i].position, birds->destPos[i]);
|
||||
UpdatePhysics(&birds->physics[i], dir);
|
||||
printf("birdsPos: %f, %f", birds->physics[i].position.x, birds->physics[i].position.y);
|
||||
printf("cameraTarget: %f, %f",camera->target.x, camera->target.y );
|
||||
UpdateSpriteDestRec(&birds->sprite[i], &birds->physics[i].position);
|
||||
float rotation = Vector2ToRotation(dir);
|
||||
UpdateSpriteRotation(&birds->sprite[i], rotation + 45.0f);
|
||||
|
||||
@@ -0,0 +1,89 @@
|
||||
#include "appTypes.h"
|
||||
#include "engine.h"
|
||||
|
||||
const TextureAsset enemiesTextureAssets[ENEMIES_TEX_COUNT] = {
|
||||
{"assets/ship_start.png", 16.0f, 16.0f, 0.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;
|
||||
|
||||
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
|
||||
};
|
||||
|
||||
Rectangle cameraRec = GetCameraRectangle();
|
||||
|
||||
enemies.physics[i] = (Physics){
|
||||
.position = GetPositionOutsideRectangle(cameraRec, 100, 1000),
|
||||
.direction = (Vector2){0.0f, 0.0f},
|
||||
.speed = 5.0f
|
||||
};
|
||||
|
||||
enemies.arrived[i] = true;
|
||||
enemies.destPos[i] = (Vector2){0.0f, 0.0f};
|
||||
|
||||
}
|
||||
|
||||
return enemies;
|
||||
}
|
||||
|
||||
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 + 45.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]);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,6 @@ Rectangle GetCameraRectangle(void)
|
||||
float viewHeight = 0.0f;
|
||||
float viewX = 0.0f;
|
||||
float viewY = 0.0f;
|
||||
printf("\n CameraZoom: %f \n", camera->zoom);
|
||||
if (camera->zoom < 0.5f)
|
||||
{
|
||||
viewWidth = screenWidth;
|
||||
|
||||
Reference in New Issue
Block a user