12.02.25
This commit is contained in:
@@ -1,2 +0,0 @@
|
|||||||
# Auto detect text files and perform LF normalization
|
|
||||||
* text=auto
|
|
||||||
@@ -1,32 +1,15 @@
|
|||||||
CXX = clang
|
COMPILER = clang
|
||||||
EMCC = emcc
|
C_FLAGS = -std=c99 -g -Wall -Werror -Wpedantic -Wconversion -Wshadow -Wstrict-prototypes -fsanitize=address,undefined -O0
|
||||||
FLAGS = -std=c99 -g -Wall -Werror -Wpedantic -Wconversion -Wshadow -Wstrict-prototypes -fsanitize=address,undefined -O0 $(shell pkg-config --libs --cflags raylib)
|
RAYLIB_FLAGS = $(shell pkg-config --libs --cflags raylib)
|
||||||
SRC = scripts/main.c
|
SRC = scripts/main.c
|
||||||
|
TARGET = bin/game
|
||||||
|
|
||||||
# ARM Build
|
build: $(TARGET)
|
||||||
ARM_TARGET = bin/game
|
$(TARGET): $(SRC)
|
||||||
arm: $(ARM_TARGET)
|
$(COMPILER) $(FLAGS) $(RAYLIB_FLAGS) $(SRC) -o $(TARGET)
|
||||||
$(ARM_TARGET): $(SRC)
|
|
||||||
$(CXX) $(FLAGS) $(SRC) -o $(ARM_TARGET)
|
|
||||||
|
|
||||||
# Web Build
|
|
||||||
WEB_TARGET = bin/game.js
|
|
||||||
EMFLAGS = -s USE_GLFW=3 -s ASYNCIFY -s TOTAL_MEMORY=67108864 \
|
|
||||||
--preload-file assets -DPLATFORM_WEB -gsource-map -s ASSERTIONS=2
|
|
||||||
RAYLIB_WEB_PATH = web-includes
|
|
||||||
web: $(WEB_TARGET)
|
|
||||||
$(WEB_TARGET): $(SRC)
|
|
||||||
$(EMCC) -Wall -std=c++17 -I/opt/homebrew/include -L$(RAYLIB_WEB_PATH) \
|
|
||||||
-lraylib.web $(SRC) -o $(WEB_TARGET) $(EMFLAGS)
|
|
||||||
|
|
||||||
# Clean
|
|
||||||
clean:
|
clean:
|
||||||
rm -f $(ARM_TARGET) $(WEB_TARGET)
|
rm -f $(TARGET)
|
||||||
|
|
||||||
# Run ARM Build
|
run: clean build
|
||||||
run: clean arm
|
./$(TARGET)
|
||||||
./$(ARM_TARGET)
|
|
||||||
|
|
||||||
# Serve Web Build
|
|
||||||
serve: web
|
|
||||||
python3 -m http.server
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
[remap]
|
|
||||||
|
|
||||||
importer="texture"
|
|
||||||
type="CompressedTexture2D"
|
|
||||||
uid="uid://n72g6l4saupl"
|
|
||||||
path="res://.godot/imported/character.png-7d161e056639ffa8fae932e906cc0673.ctex"
|
|
||||||
metadata={
|
|
||||||
"vram_texture": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[deps]
|
|
||||||
|
|
||||||
source_file="res://assets/character.png"
|
|
||||||
dest_files=["res://.godot/imported/character.png-7d161e056639ffa8fae932e906cc0673.ctex"]
|
|
||||||
|
|
||||||
[params]
|
|
||||||
|
|
||||||
compress/mode=0
|
|
||||||
compress/high_quality=false
|
|
||||||
compress/lossy_quality=0.7
|
|
||||||
compress/hdr_compression=1
|
|
||||||
compress/normal_map=0
|
|
||||||
compress/channel_pack=0
|
|
||||||
mipmaps/generate=false
|
|
||||||
mipmaps/limit=-1
|
|
||||||
roughness/mode=0
|
|
||||||
roughness/src_normal=""
|
|
||||||
process/fix_alpha_border=true
|
|
||||||
process/premult_alpha=false
|
|
||||||
process/normal_map_invert_y=false
|
|
||||||
process/hdr_as_srgb=false
|
|
||||||
process/hdr_clamp_exposure=false
|
|
||||||
process/size_limit=0
|
|
||||||
detect_3d/compress_to=1
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
[remap]
|
|
||||||
|
|
||||||
importer="texture"
|
|
||||||
type="CompressedTexture2D"
|
|
||||||
uid="uid://clxsj5chse86r"
|
|
||||||
path="res://.godot/imported/map.png-dfba05084e3346587240e6093ee94fb2.ctex"
|
|
||||||
metadata={
|
|
||||||
"vram_texture": false
|
|
||||||
}
|
|
||||||
|
|
||||||
[deps]
|
|
||||||
|
|
||||||
source_file="res://assets/map.png"
|
|
||||||
dest_files=["res://.godot/imported/map.png-dfba05084e3346587240e6093ee94fb2.ctex"]
|
|
||||||
|
|
||||||
[params]
|
|
||||||
|
|
||||||
compress/mode=0
|
|
||||||
compress/high_quality=false
|
|
||||||
compress/lossy_quality=0.7
|
|
||||||
compress/hdr_compression=1
|
|
||||||
compress/normal_map=0
|
|
||||||
compress/channel_pack=0
|
|
||||||
mipmaps/generate=false
|
|
||||||
mipmaps/limit=-1
|
|
||||||
roughness/mode=0
|
|
||||||
roughness/src_normal=""
|
|
||||||
process/fix_alpha_border=true
|
|
||||||
process/premult_alpha=false
|
|
||||||
process/normal_map_invert_y=false
|
|
||||||
process/hdr_as_srgb=false
|
|
||||||
process/hdr_clamp_exposure=false
|
|
||||||
process/size_limit=0
|
|
||||||
detect_3d/compress_to=1
|
|
||||||
@@ -1,41 +0,0 @@
|
|||||||
#ifndef ANIMSPRITE_H
|
|
||||||
#define ANIMSPRITE_H
|
|
||||||
#include <raylib.h>
|
|
||||||
#include "sprite.h"
|
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
Sprite sprite;
|
|
||||||
int currentFrame;
|
|
||||||
int maxFrame;
|
|
||||||
int framesCounter;
|
|
||||||
int framesSpeed;
|
|
||||||
float animTimer;
|
|
||||||
bool isVertical;
|
|
||||||
} AnimSprite;
|
|
||||||
|
|
||||||
void UpdateAnimSprite(AnimSprite *animSprite) {
|
|
||||||
animSprite->animTimer += GetFrameTime();
|
|
||||||
float frameTime = 1.0f / animSprite->framesSpeed;
|
|
||||||
|
|
||||||
if (animSprite->animTimer < frameTime) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
animSprite->animTimer -= frameTime;
|
|
||||||
animSprite->currentFrame++;
|
|
||||||
|
|
||||||
if (animSprite->currentFrame >= animSprite->maxFrame) {
|
|
||||||
animSprite->currentFrame = 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
Vector2 newFramePos = {
|
|
||||||
.x = animSprite->isVertical ? animSprite->sprite.sourceRec.x
|
|
||||||
: animSprite->currentFrame * animSprite->sprite.frameSize.x,
|
|
||||||
.y = animSprite->isVertical ? animSprite->currentFrame * animSprite->sprite.frameSize.y
|
|
||||||
: animSprite->sprite.sourceRec.y
|
|
||||||
};
|
|
||||||
|
|
||||||
UpdateSpriteSourceRec(&animSprite->sprite, &newFramePos);
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif // ANIMSPRITE_H
|
|
||||||
+114
-121
@@ -1,79 +1,47 @@
|
|||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
// WHITE, Color,
|
|
||||||
// KEY_RIGHT, KEY_LEFT, KEY_DOWN, KEY_UP, IsKeyDown(),
|
|
||||||
// InitWindow(), SetTargetFPS(), WindowShouldClose(), GetFrameTime(), CloseWindow()
|
|
||||||
// Music, InitAudioDevice(), LoadMusicStream(), PlayMusicStream(), UpdateMusicStream(), UnloadMusicStream(), CloseAudioDevice(),
|
|
||||||
// Texture2D, Rectangle, Vector2, LoadTexture(), DrawTexturePro(), UnloadTexture(),
|
|
||||||
// BeginDrawing(), EndDrawing(), ClearBackground(),
|
|
||||||
// Camera2D, BeginMode2D(), EndMode2D()
|
|
||||||
#include <raymath.h> // Vector2Length(), Vector2Normalize(), Vector2Add(), Vector2Scale(), Lerp()
|
|
||||||
#include <stdlib.h> // rand(), srand(), malloc()
|
|
||||||
#include <time.h> // time()
|
|
||||||
#include <string.h> // memcpy()
|
|
||||||
|
|
||||||
#include "sprite.h"
|
#include "sprite.h"
|
||||||
#include "animsprite.h"
|
#include "animation.h"
|
||||||
#include "tilesprite.h"
|
#include "tilesprite.h"
|
||||||
#include "vector.h"
|
#include "vector.h"
|
||||||
#include "object.h"
|
#include "object.h"
|
||||||
|
#include "physics.h"
|
||||||
|
#include "camera.h"
|
||||||
|
#include "input.h"
|
||||||
|
|
||||||
// Structs
|
// Structs
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
AnimSprite animSprite;
|
Sprite sprite;
|
||||||
Vector2 position;
|
Animation animation;
|
||||||
Vector2 direction;
|
Physics physics;
|
||||||
float velocity;
|
|
||||||
} Player;
|
} Player;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
AnimSprite animSprite;
|
Sprite sprite;
|
||||||
Vector2 position;
|
Animation animation;
|
||||||
Vector2 direction;
|
Physics physics;
|
||||||
float velocity;
|
Object target;
|
||||||
Object targetFlower;
|
|
||||||
Object hive;
|
Object hive;
|
||||||
|
int flowerCount;
|
||||||
} Bee;
|
} Bee;
|
||||||
|
|
||||||
// Pure functions
|
|
||||||
|
|
||||||
|
|
||||||
void Move(Vector2 *position, Vector2 *direction, float *velocity, float *rotation) {
|
|
||||||
if(Vector2Length(*direction) <= 0.0f){
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
float targetRotation = (float)atan2(direction->y, direction->x) * (180.0f / PI) + 90.0f;
|
|
||||||
*rotation = Lerp(*rotation, targetRotation, 0.1f);
|
|
||||||
*position = Vector2Add(*position, Vector2Scale(*direction, *velocity * GetFrameTime()));
|
|
||||||
}
|
|
||||||
|
|
||||||
// Mutator Functions
|
|
||||||
|
|
||||||
void GetDirectionFromInput(Vector2 *direction){
|
|
||||||
*direction = (Vector2){0.0f, 0.0f};
|
|
||||||
if (IsKeyDown(KEY_RIGHT) || IsKeyDown(KEY_D)){ direction->x += 1.0f; }
|
|
||||||
if (IsKeyDown(KEY_LEFT) || IsKeyDown(KEY_A)){ direction->x -= 1.0f; }
|
|
||||||
if (IsKeyDown(KEY_DOWN) || IsKeyDown(KEY_S)){ direction->y += 1.0f; }
|
|
||||||
if (IsKeyDown(KEY_UP) || IsKeyDown(KEY_W)){ direction->y -= 1.0f; }
|
|
||||||
if (Vector2Length(*direction) > 0.0f) { *direction = Vector2Normalize(*direction); }
|
|
||||||
}
|
|
||||||
|
|
||||||
void UpdateCamera2DTarget(Camera2D *camera, Vector2 *position, const float smoothness){
|
|
||||||
camera->target = Vector2Lerp(camera->target, *position, smoothness * GetFrameTime());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Main
|
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
{
|
{
|
||||||
// Load
|
// Load
|
||||||
// SetConfigFlags(FLAG_VSYNC_HINT);
|
|
||||||
InitWindow(1280, 720, "The Last Hive");
|
InitWindow(1280, 720, "The Last Hive");
|
||||||
|
|
||||||
InitAudioDevice();
|
InitAudioDevice();
|
||||||
Music music = LoadMusicStream("assets/beez.mp3");
|
Music music = LoadMusicStream("assets/beez.mp3");
|
||||||
PlayMusicStream(music);
|
PlayMusicStream(music);
|
||||||
|
|
||||||
|
Texture2D flowerTexture = LoadTexture("assets/flower.png");
|
||||||
|
Texture2D beeTexture = LoadTexture("assets/character_bee.png");
|
||||||
|
Texture2D floorTexture = LoadTexture("assets/grass.png");
|
||||||
|
Texture2D hiveTexture = LoadTexture("assets/hive.png");
|
||||||
|
|
||||||
TileSprite floor = {
|
TileSprite floor = {
|
||||||
.sprite = {
|
.sprite = {
|
||||||
.texture = LoadTexture("assets/grass.png"),
|
.texture = floorTexture,
|
||||||
.frameSize = {16.0f,16.0f},
|
.frameSize = {16.0f,16.0f},
|
||||||
.sourceRec = { 0.0f, 0.0f, 16.0f, 16.0f},
|
.sourceRec = { 0.0f, 0.0f, 16.0f, 16.0f},
|
||||||
.destRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
.destRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
||||||
@@ -83,9 +51,10 @@ int main(void)
|
|||||||
},
|
},
|
||||||
.bounds = {0.0f,0.0f,0.0f,0.0f}
|
.bounds = {0.0f,0.0f,0.0f,0.0f}
|
||||||
};
|
};
|
||||||
|
|
||||||
Object hive = {
|
Object hive = {
|
||||||
.sprite = {
|
.sprite = {
|
||||||
.texture = LoadTexture("assets/hive.png"),
|
.texture = hiveTexture,
|
||||||
.frameSize = {32.0f,32.0f},
|
.frameSize = {32.0f,32.0f},
|
||||||
.sourceRec = {0.0f, 0.0f, 32.0f, 32.0f},
|
.sourceRec = {0.0f, 0.0f, 32.0f, 32.0f},
|
||||||
.destRec = {0.0f, 0.0f, 32.0f, 32.0f},
|
.destRec = {0.0f, 0.0f, 32.0f, 32.0f},
|
||||||
@@ -95,10 +64,10 @@ int main(void)
|
|||||||
},
|
},
|
||||||
.position = (Vector2){0.0f,0.0f}
|
.position = (Vector2){0.0f,0.0f}
|
||||||
};
|
};
|
||||||
Texture2D flower = LoadTexture("assets/flower.png");
|
|
||||||
ObjectArray flowers = CreateObjectArray(&(Object){
|
ObjectArray flowers = CreateObjectArray(&(Object){
|
||||||
.sprite = {
|
.sprite = {
|
||||||
.texture = flower,
|
.texture = flowerTexture,
|
||||||
.frameSize = {16.0f, 16.0f},
|
.frameSize = {16.0f, 16.0f},
|
||||||
.sourceRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
.sourceRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
||||||
.destRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
.destRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
||||||
@@ -107,106 +76,131 @@ int main(void)
|
|||||||
.color = WHITE
|
.color = WHITE
|
||||||
},
|
},
|
||||||
.position = {0.0f, 0.0f}
|
.position = {0.0f, 0.0f}
|
||||||
}, 300);
|
}, 10);
|
||||||
if (!flowers.data) {
|
if (!flowers.data) {
|
||||||
printf("Memory allocation failed.\n");
|
printf("Memory allocation failed.\n");
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
Rectangle flowerField = {-50.0f, -50.0f, 100.0f, 100.0f};
|
Rectangle flowerField = {-50.0f, -50.0f, 100.0f, 100.0f};
|
||||||
SetRandomPositionForObjectArray(&flowers, flowerField);
|
SetRandomPositionForObjectArray(&flowers, flowerField);
|
||||||
|
|
||||||
Player player = {
|
Player player = {
|
||||||
.animSprite = {
|
.sprite = {
|
||||||
.sprite = {
|
.texture = beeTexture,
|
||||||
.texture = LoadTexture("assets/character_bee.png"),
|
.frameSize = {16.0f, 16.0f},
|
||||||
.frameSize = {16.0f, 16.0f},
|
.sourceRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
||||||
.sourceRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
.destRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
||||||
.destRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
.origin = {8.0f, 8.0f},
|
||||||
.origin = {8.0f, 8.0f},
|
.rotation = 0.0f,
|
||||||
.rotation = 0.0f,
|
.color = WHITE
|
||||||
.color = WHITE
|
},
|
||||||
},
|
.animation = {
|
||||||
.currentFrame = 0,
|
.currentFrame = 0,
|
||||||
.maxFrame = 4,
|
.maxFrame = 4,
|
||||||
.framesCounter = 0,
|
.framesCounter = 0,
|
||||||
.framesSpeed = 10,
|
.framesSpeed = 10,
|
||||||
.isVertical = true,
|
|
||||||
.animTimer = 0.0f
|
.animTimer = 0.0f
|
||||||
},
|
},
|
||||||
.position = hive.position,
|
.physics = {
|
||||||
.direction = (Vector2){0.0f,0.0f},
|
.position = hive.position,
|
||||||
.velocity = 50.0f
|
.direction = (Vector2){0.0f,0.0f},
|
||||||
|
.speed = 50.0f
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
Bee bee1 = {
|
Bee bee1 = {
|
||||||
.animSprite = {
|
.sprite = {
|
||||||
.sprite = {
|
.texture = beeTexture,
|
||||||
.texture = LoadTexture("assets/character_bee.png"),
|
.frameSize = {16.0f, 16.0f},
|
||||||
.frameSize = {16.0f, 16.0f},
|
.sourceRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
||||||
.sourceRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
.destRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
||||||
.destRec = {0.0f, 0.0f, 16.0f, 16.0f},
|
.origin = {8.0f, 8.0f},
|
||||||
.origin = {8.0f, 8.0f},
|
.rotation = 0.0f,
|
||||||
.rotation = 0.0f,
|
.color = WHITE
|
||||||
.color = WHITE
|
},
|
||||||
},
|
.animation = {
|
||||||
.currentFrame = 0,
|
.currentFrame = 0,
|
||||||
.maxFrame = 4,
|
.maxFrame = 4,
|
||||||
.framesCounter = 0,
|
.framesCounter = 0,
|
||||||
.framesSpeed = 10,
|
.framesSpeed = 10,
|
||||||
.isVertical = true,
|
|
||||||
.animTimer = 0.0f
|
.animTimer = 0.0f
|
||||||
},
|
},
|
||||||
.position = hive.position,
|
.physics = {
|
||||||
.direction = (Vector2){0.0f,0.0f},
|
.position = hive.position,
|
||||||
.velocity = 5.0f,
|
.direction = (Vector2){0.0f,0.0f},
|
||||||
.targetFlower = *GetRandomObject(&flowers),
|
.speed = 10.0f
|
||||||
|
},
|
||||||
|
.target = *GetRandomObject(&flowers),
|
||||||
.hive = hive
|
.hive = hive
|
||||||
};
|
};
|
||||||
|
|
||||||
Camera2D camera = {
|
Camera2D camera = {
|
||||||
.offset = (Vector2){GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f},
|
.offset = (Vector2){GetScreenWidth() / 2.0f, GetScreenHeight() / 2.0f},
|
||||||
.target = player.position,
|
.target = player.physics.position,
|
||||||
.rotation = 0.0f,
|
.rotation = 0.0f,
|
||||||
.zoom = 10.0f
|
.zoom = 10.0f
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Mouse mouse = {
|
||||||
|
.zoomSpeed = 0.10f,
|
||||||
|
.minZoom = 5.0f,
|
||||||
|
.maxZoom = 10.0f
|
||||||
|
};
|
||||||
|
|
||||||
// Update & Render
|
// Update & Render
|
||||||
while (!WindowShouldClose())
|
while (!WindowShouldClose())
|
||||||
{
|
{
|
||||||
// Update
|
// Update
|
||||||
if (IsMouseButtonPressed(MOUSE_LEFT_BUTTON)) {
|
|
||||||
Vector2 mouseWorldPos = GetScreenToWorld2D(GetMousePosition(), camera);
|
|
||||||
AddObjectToArray(&flowers, flowers.prototype, mouseWorldPos);
|
|
||||||
}
|
|
||||||
|
|
||||||
UpdateMusicStream(music);
|
UpdateMusicStream(music);
|
||||||
|
|
||||||
UpdateTileSpriteBounds(&floor, &camera);
|
UpdateTileSpriteBounds(&floor, &camera);
|
||||||
|
|
||||||
GetDirectionFromInput(&player.direction);
|
|
||||||
Move(&player.position, &player.direction, &player.velocity, &player.animSprite.sprite.rotation);
|
|
||||||
UpdateSpriteDestRec(&player.animSprite.sprite, &player.position);
|
|
||||||
UpdateAnimSprite(&player.animSprite);
|
|
||||||
|
|
||||||
const float tolerance = 1.0f; // Adjust as needed
|
UpdateMouse(&mouse, &camera);
|
||||||
|
|
||||||
if (fabs(bee1.position.x - bee1.targetFlower.position.x) < tolerance &&
|
if (mouse.leftButton) {
|
||||||
fabs(bee1.position.y - bee1.targetFlower.position.y) < tolerance) {
|
AddObjectToArray(&flowers, flowers.prototype, mouse.worldPosition);
|
||||||
bee1.velocity = 0.0f;
|
|
||||||
} else {
|
|
||||||
Move(&bee1.position, &bee1.direction, &bee1.velocity, &bee1.animSprite.sprite.rotation);
|
|
||||||
bee1.direction = GetDirectionToObject(&bee1.targetFlower, bee1.position);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
UpdateSpriteDestRec(&bee1.animSprite.sprite, &bee1.position);
|
UpdateVectorOnInput(&player.physics.direction);
|
||||||
UpdateAnimSprite(&bee1.animSprite);
|
Move(&player.physics.position, &player.physics.direction, &player.physics.speed);
|
||||||
|
UpdateSpriteRotation(&player.sprite, &player.physics.direction);
|
||||||
|
UpdateSpriteDestRec(&player.sprite, &player.physics.position);
|
||||||
|
UpdateAnimation(&player.animation, GetFrameTime());
|
||||||
|
UpdateSpriteSourceRec(&player.sprite, &(Vector2){player.sprite.frameSize.x, player.sprite.frameSize.x * player.animation.currentFrame});
|
||||||
|
|
||||||
UpdateCamera2DTarget(&camera, &player.position, 5.0f);
|
const float tolerance = 1.0f;
|
||||||
|
|
||||||
float wheel = GetMouseWheelMove();
|
if (bee1.flowerCount < 4){
|
||||||
if (wheel != 0)
|
if (fabs(bee1.physics.position.x - bee1.target.position.x) < tolerance &&
|
||||||
|
fabs(bee1.physics.position.y - bee1.target.position.y) < tolerance) {
|
||||||
|
bee1.target = *GetRandomObject(&flowers);
|
||||||
|
bee1.flowerCount++;
|
||||||
|
} else {
|
||||||
|
Move(&bee1.physics.position, &bee1.physics.direction, &bee1.physics.speed);
|
||||||
|
UpdateSpriteRotation(&bee1.sprite, &bee1.physics.direction);
|
||||||
|
bee1.physics.direction = GetDirectionToObject(&bee1.target, bee1.physics.position);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
bee1.target = hive;
|
||||||
|
if (fabs(bee1.physics.position.x - bee1.target.position.x) < tolerance &&
|
||||||
|
fabs(bee1.physics.position.y - bee1.target.position.y) < tolerance) {
|
||||||
|
bee1.physics.speed = 0.0f;
|
||||||
|
} else {
|
||||||
|
Move(&bee1.physics.position, &bee1.physics.direction, &bee1.physics.speed);
|
||||||
|
UpdateSpriteRotation(&bee1.sprite, &bee1.physics.direction);
|
||||||
|
bee1.physics.direction = GetDirectionToObject(&bee1.target, bee1.physics.position);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
UpdateSpriteDestRec(&bee1.sprite, &bee1.physics.position);
|
||||||
|
UpdateAnimation(&bee1.animation, GetFrameTime());
|
||||||
|
UpdateSpriteSourceRec(&bee1.sprite, &(Vector2){bee1.sprite.frameSize.x, bee1.sprite.frameSize.x * bee1.animation.currentFrame});
|
||||||
|
|
||||||
|
UpdateCamera2DTarget(&camera, &player.physics.position, 5.0f);
|
||||||
|
|
||||||
|
if (mouse.wheelMove != 0)
|
||||||
{
|
{
|
||||||
float zoomSpeed = 0.10f;
|
UpdateCamera2DZoom(&camera, &mouse.scaleFactor, &mouse.minZoom, &mouse.maxZoom);
|
||||||
float scaleFactor = 1.0f + (zoomSpeed*fabsf(wheel));
|
|
||||||
if (wheel < 0) scaleFactor = 1.0f/scaleFactor;
|
|
||||||
float targetZoom = Clamp(camera.zoom*scaleFactor, 5.0f, 10.0f);
|
|
||||||
camera.zoom = Lerp(camera.zoom, targetZoom, 0.1f);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render
|
// Render
|
||||||
@@ -216,18 +210,17 @@ int main(void)
|
|||||||
RenderTileSprite(&floor);
|
RenderTileSprite(&floor);
|
||||||
RenderSprite(&hive.sprite);
|
RenderSprite(&hive.sprite);
|
||||||
RenderObjectArray(&flowers);
|
RenderObjectArray(&flowers);
|
||||||
RenderSprite(&bee1.animSprite.sprite);
|
RenderSprite(&bee1.sprite);
|
||||||
RenderSprite(&player.animSprite.sprite);
|
RenderSprite(&player.sprite);
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
DrawFPS(10,10);
|
DrawFPS(10,10);
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
// Unload
|
// Unload
|
||||||
UnloadTexture(floor.sprite.texture);
|
UnloadTexture(floorTexture);
|
||||||
UnloadTexture(hive.sprite.texture);
|
UnloadTexture(hiveTexture);
|
||||||
UnloadTexture(flower);
|
UnloadTexture(flowerTexture);
|
||||||
UnloadTexture(bee1.animSprite.sprite.texture);
|
UnloadTexture(beeTexture);
|
||||||
UnloadTexture(player.animSprite.sprite.texture);
|
|
||||||
UnloadMusicStream(music);
|
UnloadMusicStream(music);
|
||||||
free(flowers.data);
|
free(flowers.data);
|
||||||
// Close
|
// Close
|
||||||
|
|||||||
@@ -3,7 +3,6 @@
|
|||||||
#include <raylib.h>
|
#include <raylib.h>
|
||||||
#include <raymath.h>
|
#include <raymath.h>
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
Vector2 position;
|
Vector2 position;
|
||||||
Vector2 direction;
|
Vector2 direction;
|
||||||
|
|||||||
Reference in New Issue
Block a user