[Added] Crates, Hud for bullets and health
This commit is contained in:
@@ -28,7 +28,8 @@
|
|||||||
"settings": {},
|
"settings": {},
|
||||||
"extensions": [
|
"extensions": [
|
||||||
"esbenp.prettier-vscode",
|
"esbenp.prettier-vscode",
|
||||||
"ms-vscode.cpptools-extension-pack"
|
"ms-vscode.cpptools-extension-pack",
|
||||||
|
"vadimcn.vscode-lldb"
|
||||||
]
|
]
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
Vendored
+23
@@ -0,0 +1,23 @@
|
|||||||
|
{
|
||||||
|
"version": "0.2.0",
|
||||||
|
"configurations": [
|
||||||
|
{
|
||||||
|
"name": "Debug with LLDB",
|
||||||
|
"type": "lldb",
|
||||||
|
"request": "launch",
|
||||||
|
"program": "${workspaceFolder}/dist/jelly_rescue",
|
||||||
|
"args": [],
|
||||||
|
"cwd": "${workspaceFolder}",
|
||||||
|
"stopAtEntry": false,
|
||||||
|
"miDebuggerPath": "/usr/bin/lldb-mi",
|
||||||
|
"preLaunchTask": "build jelly_rescue",
|
||||||
|
"setupCommands": [
|
||||||
|
{
|
||||||
|
"description": "Enable pretty-printing for gdb",
|
||||||
|
"text": "-enable-pretty-printing",
|
||||||
|
"ignoreFailures": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
Vendored
+20
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"version": "2.0.0",
|
||||||
|
"tasks": [
|
||||||
|
{
|
||||||
|
"label": "build jelly_rescue",
|
||||||
|
"type": "shell",
|
||||||
|
"command": "bash",
|
||||||
|
"args": [
|
||||||
|
"-c",
|
||||||
|
"g++ -std=c++20 -g -O0 $(find src/ -name \"*.cpp\") -o dist/jelly_rescue -I./include -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11"
|
||||||
|
],
|
||||||
|
"group": {
|
||||||
|
"kind": "build",
|
||||||
|
"isDefault": true
|
||||||
|
},
|
||||||
|
"problemMatcher": ["$gcc"],
|
||||||
|
"detail": "Compiling the jelly_rescue project"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
+1
-1
@@ -8,7 +8,7 @@ RUN apt-get update \
|
|||||||
cmake \
|
cmake \
|
||||||
libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev \
|
libasound2-dev libx11-dev libxrandr-dev libxi-dev libgl1-mesa-dev \
|
||||||
libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev \
|
libglu1-mesa-dev libxcursor-dev libxinerama-dev libwayland-dev libxkbcommon-dev \
|
||||||
sudo \
|
sudo lldb \
|
||||||
alsa-utils \
|
alsa-utils \
|
||||||
&& rm -rf /var/cache/apt/*
|
&& rm -rf /var/cache/apt/*
|
||||||
|
|
||||||
|
|||||||
@@ -16,7 +16,6 @@ public:
|
|||||||
{
|
{
|
||||||
this->position = pos;
|
this->position = pos;
|
||||||
this->direction = direction;
|
this->direction = direction;
|
||||||
std::cout << direction << std::endl;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// ~Bullet() {}
|
// ~Bullet() {}
|
||||||
@@ -25,8 +24,8 @@ public:
|
|||||||
{
|
{
|
||||||
move();
|
move();
|
||||||
hasCollided = false;
|
hasCollided = false;
|
||||||
envCollision();
|
|
||||||
objCollision();
|
objCollision();
|
||||||
|
envCollision();
|
||||||
// // detectCollision();
|
// // detectCollision();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -42,14 +41,14 @@ public:
|
|||||||
|
|
||||||
protected:
|
protected:
|
||||||
Color color = RED;
|
Color color = RED;
|
||||||
|
Vector2 position;
|
||||||
|
int size = 7;
|
||||||
|
bool hasCollided = false;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// TextureWrapper object;
|
// TextureWrapper object;
|
||||||
Vector2 position;
|
|
||||||
float direction;
|
float direction;
|
||||||
float velocity = 15.0f;
|
float velocity = 15.0f;
|
||||||
int size = 7;
|
|
||||||
bool hasCollided = false;
|
|
||||||
|
|
||||||
void move()
|
void move()
|
||||||
{
|
{
|
||||||
@@ -59,7 +58,7 @@ private:
|
|||||||
}
|
}
|
||||||
void envCollision()
|
void envCollision()
|
||||||
{
|
{
|
||||||
if (position.y < 0 || position.y > GetScreenHeight())
|
if (position.x < 0 || position.y < 0 || position.y > GetScreenHeight())
|
||||||
{
|
{
|
||||||
hasCollided = true;
|
hasCollided = true;
|
||||||
return;
|
return;
|
||||||
|
|||||||
@@ -0,0 +1,48 @@
|
|||||||
|
#ifndef CRATE_H
|
||||||
|
#define CRATE_H
|
||||||
|
|
||||||
|
#include "services/AssetService.h"
|
||||||
|
#include "entities/TextureWrapper.h"
|
||||||
|
#include "entities/PBullet.h"
|
||||||
|
|
||||||
|
class Crate {
|
||||||
|
public:
|
||||||
|
Crate() {
|
||||||
|
this->texture = TextureWrapper(AssetService::getInstance().getSprite(ESprite::CRATE),{32,32});
|
||||||
|
}
|
||||||
|
|
||||||
|
Crate(Vector2 pos) {
|
||||||
|
this->texture = TextureWrapper(AssetService::getInstance().getSprite(ESprite::CRATE),{32,32}, pos);
|
||||||
|
}
|
||||||
|
|
||||||
|
void logic() {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
bool hasBeenHit() {
|
||||||
|
return this->hit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void setHit(bool hit) {
|
||||||
|
this->hit = hit;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw() {
|
||||||
|
DrawTexture(this->texture.getTexture(), this->texture.getPosition().x, this->texture.getPosition().y, WHITE);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextureWrapper& getObject() {
|
||||||
|
return this->texture;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
TextureWrapper texture;
|
||||||
|
bool hit; // Whether a PBullet has hit the create
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#endif
|
||||||
+65
-4
@@ -8,6 +8,7 @@
|
|||||||
#include "services/MapService.h"
|
#include "services/MapService.h"
|
||||||
#include "services/InputService.h"
|
#include "services/InputService.h"
|
||||||
#include "services/GameService.h"
|
#include "services/GameService.h"
|
||||||
|
#include "services/CollectableService.h"
|
||||||
#include "entities/Player.h"
|
#include "entities/Player.h"
|
||||||
#include "entities/Text.h"
|
#include "entities/Text.h"
|
||||||
#include "entities/Bullet.h"
|
#include "entities/Bullet.h"
|
||||||
@@ -47,6 +48,8 @@ public:
|
|||||||
this->player.setPosition({200, 350});
|
this->player.setPosition({200, 350});
|
||||||
this->crosshair = TextureWrapper(AssetService::getInstance().getSprite(ESprite::CROSSHAIR), {15, 15}, {0, 0}, {0, 0, 15, 15});
|
this->crosshair = TextureWrapper(AssetService::getInstance().getSprite(ESprite::CROSSHAIR), {15, 15}, {0, 0}, {0, 0, 15, 15});
|
||||||
|
|
||||||
|
CollectableService::getInstance().initCollectables();
|
||||||
|
|
||||||
initPauseScreen();
|
initPauseScreen();
|
||||||
initGameOverScreen();
|
initGameOverScreen();
|
||||||
|
|
||||||
@@ -82,6 +85,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
GameService::getInstance().bulletLogic();
|
GameService::getInstance().bulletLogic();
|
||||||
|
CollectableService::getInstance().collectableLogic();
|
||||||
|
|
||||||
this->player.logic();
|
this->player.logic();
|
||||||
if (this->player.getTexture().getPosition().x > (StateService::getInstance().getScreenSize().x / 2.0f))
|
if (this->player.getTexture().getPosition().x > (StateService::getInstance().getScreenSize().x / 2.0f))
|
||||||
@@ -104,6 +108,7 @@ public:
|
|||||||
// }
|
// }
|
||||||
GameService::getInstance().drawBullets();
|
GameService::getInstance().drawBullets();
|
||||||
this->map.draw();
|
this->map.draw();
|
||||||
|
CollectableService::getInstance().drawCollectables();
|
||||||
this->player.draw();
|
this->player.draw();
|
||||||
|
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
@@ -116,6 +121,7 @@ public:
|
|||||||
{
|
{
|
||||||
drawGameOver();
|
drawGameOver();
|
||||||
}
|
}
|
||||||
|
drawHud();
|
||||||
drawCrosshair();
|
drawCrosshair();
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
@@ -250,10 +256,6 @@ private:
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void shootLogic()
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
void drawPaused()
|
void drawPaused()
|
||||||
{
|
{
|
||||||
// 100, 100, 255, 60
|
// 100, 100, 255, 60
|
||||||
@@ -290,6 +292,65 @@ private:
|
|||||||
// 0,
|
// 0,
|
||||||
// WHITE);
|
// WHITE);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void drawHud()
|
||||||
|
{
|
||||||
|
drawHudHealth();
|
||||||
|
drawHudBullets();
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawHudBullets()
|
||||||
|
{
|
||||||
|
Vector2i pixel_pos = Vector2i(5, 40);
|
||||||
|
Texture2D ammoSprite = AssetService::getInstance().getSprite(ESprite::HUD_AMMO);
|
||||||
|
Vector2i display_pos;
|
||||||
|
for (int i = 0; i < this->player.getAmmo(); i++)
|
||||||
|
{
|
||||||
|
if (i <= 49)
|
||||||
|
{
|
||||||
|
display_pos = Vector2i(pixel_pos.x + ammoSprite.width * i, pixel_pos.y);
|
||||||
|
}
|
||||||
|
if (i > 49 && i <= 99)
|
||||||
|
{
|
||||||
|
display_pos = Vector2i(pixel_pos.x + ammoSprite.width * (i - (50)), pixel_pos.y + ammoSprite.height);
|
||||||
|
}
|
||||||
|
else if (i > 99 && i <= 149)
|
||||||
|
{
|
||||||
|
display_pos = Vector2i(pixel_pos.x + ammoSprite.width * (i - (100)), pixel_pos.y + ammoSprite.height * 2);
|
||||||
|
}
|
||||||
|
else if (i > 149 && i <= 199)
|
||||||
|
{
|
||||||
|
display_pos = Vector2i(pixel_pos.x + ammoSprite.width * (i - (150)), pixel_pos.y + ammoSprite.height * 3);
|
||||||
|
}
|
||||||
|
else if (i > 199 && i <= 249)
|
||||||
|
{
|
||||||
|
display_pos = Vector2i(pixel_pos.x + ammoSprite.width * (i - (200)), pixel_pos.y + ammoSprite.height * 4);
|
||||||
|
}
|
||||||
|
DrawTexture(ammoSprite, display_pos.x, display_pos.y, WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawHudHealth()
|
||||||
|
{
|
||||||
|
Vector2i pixel_pos = Vector2i(5, 5);
|
||||||
|
Texture2D noHealthSprite = AssetService::getInstance().getSprite(ESprite::HUD_HEART_EMPTY);
|
||||||
|
Texture2D healthSprite = AssetService::getInstance().getSprite(ESprite::HUD_HEART);
|
||||||
|
// sVector2f coord_pos = GetWindow().mapPixelToCoords(pixel_pos);
|
||||||
|
for (int i = 0; i < this->player.getMaxHealth(); i++)
|
||||||
|
{
|
||||||
|
Vector2i pos = Vector2i(pixel_pos.x + noHealthSprite.width * i, pixel_pos.y);
|
||||||
|
// noHealthSprite[i].setPosition(coord_pos.x + noHealthTexture.getSize().x * i, coord_pos.y);
|
||||||
|
DrawTexture(noHealthSprite, pos.x, pos.y, WHITE);
|
||||||
|
}
|
||||||
|
for (int i = 0; i < this->player.getHealth(); i++)
|
||||||
|
{
|
||||||
|
// healthSprite[i].setPosition(coord_pos.x + healthTexture.getSize().x * i, coord_pos.y);
|
||||||
|
// DrawTexture(ammoSprite, display_pos.x, display_pos.y, WHITE);
|
||||||
|
Vector2i pos = Vector2i(pixel_pos.x + healthSprite.width * i, pixel_pos.y);
|
||||||
|
// noHealthSprite[i].setPosition(coord_pos.x + noHealthTexture.getSize().x * i, coord_pos.y);
|
||||||
|
DrawTexture(healthSprite, pos.x, pos.y, WHITE);
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -1,9 +1,10 @@
|
|||||||
#ifndef MAP_H
|
#ifndef MAP_H
|
||||||
#define MAP_H
|
#define MAP_H
|
||||||
|
|
||||||
#include <vector>
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "entities/TextureWrapper.h"
|
#include "entities/TextureWrapper.h"
|
||||||
|
#include "entities/Vector2i.h"
|
||||||
|
#include <vector>
|
||||||
#include <cmath>
|
#include <cmath>
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -28,6 +29,10 @@ public:
|
|||||||
return this->colMap;
|
return this->colMap;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void updateColmapTile(Vector2i tile, bool collision) {
|
||||||
|
this->colMap[tile.y][tile.x] = collision ? 1 : 0;
|
||||||
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
/** Holds the number for every single tile, which refers to a certain sprite in the tileset */
|
/** Holds the number for every single tile, which refers to a certain sprite in the tileset */
|
||||||
std::vector<std::vector<Vector2>> map;
|
std::vector<std::vector<Vector2>> map;
|
||||||
|
|||||||
@@ -1,23 +1,35 @@
|
|||||||
#ifndef PBULLET_H
|
#ifndef PBULLET_H
|
||||||
#define PBULLET_H
|
#define PBULLET_H
|
||||||
|
|
||||||
|
#include "services/CollectableService.h"
|
||||||
|
#include "services/AssetService.h"
|
||||||
#include "entities/Bullet.h"
|
#include "entities/Bullet.h"
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
|
|
||||||
class PBullet : public Bullet {
|
class PBullet : public Bullet
|
||||||
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
PBullet() {}
|
PBullet() {}
|
||||||
PBullet(Vector2 pos, float angle) : Bullet(pos, angle) {
|
PBullet(Vector2 pos, float angle) : Bullet(pos, angle)
|
||||||
|
{
|
||||||
this->color = YELLOW;
|
this->color = YELLOW;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
void objCollision() override {
|
void objCollision() override
|
||||||
|
{
|
||||||
|
/** Check for collisions with creates */
|
||||||
|
for (auto &crate : CollectableService::getInstance().getCrates())
|
||||||
|
{
|
||||||
|
if(this->position.x + this->size > crate.getObject().getPosition().x && this->position.x - this->size < crate.getObject().getPosition().x &&
|
||||||
|
this->position.y + this->size > crate.getObject().getPosition().y && this->position.y - this->size < crate.getObject().getPosition().y ) {
|
||||||
|
crate.setHit(true);
|
||||||
|
AssetService::getInstance().playSound(ESound::CRATE_BREAK);
|
||||||
|
// AssetService::getInstance().playSound(ESound::JELLY_FREED);
|
||||||
|
this->hasCollided = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
@@ -9,6 +9,7 @@
|
|||||||
#include "services/GameService.h"
|
#include "services/GameService.h"
|
||||||
#include "entities/TextureWrapper.h"
|
#include "entities/TextureWrapper.h"
|
||||||
#include "enums/ECorner.h"
|
#include "enums/ECorner.h"
|
||||||
|
#include "enums/ESound.h"
|
||||||
#include "entities/Vector2i.h"
|
#include "entities/Vector2i.h"
|
||||||
#include "entities/PBullet.h"
|
#include "entities/PBullet.h"
|
||||||
|
|
||||||
@@ -20,11 +21,12 @@ public:
|
|||||||
this->texture = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER), {32, 32}, {200, 200});
|
this->texture = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER), {32, 32}, {200, 200});
|
||||||
|
|
||||||
prevFrame = GetTime();
|
prevFrame = GetTime();
|
||||||
spriteAnimation = {0, 0};
|
spriteAnimation = {0, Right};
|
||||||
this->gunRight = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER_GUN_RIGHT), {58, 29}, {0, 0});
|
this->gunRight = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER_GUN_RIGHT), {58, 29}, {0, 0});
|
||||||
this->gunLeft = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER_GUN_LEFT), {58, 29}, {0, 0});
|
this->gunLeft = TextureWrapper(AssetService::getInstance().getSprite(ESprite::PLAYER_GUN_LEFT), {58, 29}, {0, 0});
|
||||||
this->ammo = max_ammo;
|
this->ammo = max_ammo;
|
||||||
this->prevShot = GetTime();
|
this->prevShot = GetTime();
|
||||||
|
this->health = max_health;
|
||||||
}
|
}
|
||||||
~Player()
|
~Player()
|
||||||
{
|
{
|
||||||
@@ -54,6 +56,18 @@ public:
|
|||||||
this->texture.setPosition(pos);
|
this->texture.setPosition(pos);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int getAmmo() {
|
||||||
|
return this->ammo;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t getHealth() {
|
||||||
|
return this->health;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint8_t getMaxHealth() {
|
||||||
|
return this->max_health;
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
private:
|
private:
|
||||||
TextureWrapper texture;
|
TextureWrapper texture;
|
||||||
@@ -65,7 +79,7 @@ private:
|
|||||||
float gravity = 0.6f;
|
float gravity = 0.6f;
|
||||||
float animationDelay = 0.2f; // In seconds
|
float animationDelay = 0.2f; // In seconds
|
||||||
double prevFrame;
|
double prevFrame;
|
||||||
Vector2 spriteAnimation; // Keeps track of (1) Sprite cycling and (2) Player direction
|
Vector2i spriteAnimation; // Keeps track of (1) Sprite cycling and (2) Player direction
|
||||||
enum Direction
|
enum Direction
|
||||||
{
|
{
|
||||||
Down,
|
Down,
|
||||||
@@ -79,10 +93,12 @@ private:
|
|||||||
bool groundCollision; // Keeps track of whether or not the player has collided with the ground
|
bool groundCollision; // Keeps track of whether or not the player has collided with the ground
|
||||||
bool crateTopCollision; // Whether the player is standing on top of a crate
|
bool crateTopCollision; // Whether the player is standing on top of a crate
|
||||||
|
|
||||||
int ammo;
|
uint8_t ammo; // Current ammo of the player
|
||||||
int max_ammo = 100;
|
uint8_t max_ammo = 100; // Max ammo of the player
|
||||||
float firingRate= 0.2f; // Delay in seconds
|
float firingRate= 0.2f; // Delay in seconds
|
||||||
double prevShot; // The last time the player fired a bullet
|
double prevShot; // The last time the player fired a bullet
|
||||||
|
uint8_t health; // Current health of the player
|
||||||
|
uint8_t max_health = 10; // Max health of the player
|
||||||
|
|
||||||
void applyGravity()
|
void applyGravity()
|
||||||
{
|
{
|
||||||
@@ -278,6 +294,7 @@ private:
|
|||||||
{
|
{
|
||||||
if (this->texture.getPosition().y > StateService::getInstance().getScreenSize().y)
|
if (this->texture.getPosition().y > StateService::getInstance().getScreenSize().y)
|
||||||
{
|
{
|
||||||
|
this->health = 0;
|
||||||
GameService::getInstance().setGameOver(true);
|
GameService::getInstance().setGameOver(true);
|
||||||
AudioService::getInstance().setMusic(EMusic::GAME_OVER);
|
AudioService::getInstance().setMusic(EMusic::GAME_OVER);
|
||||||
AudioService::getInstance().playMusic();
|
AudioService::getInstance().playMusic();
|
||||||
@@ -335,14 +352,18 @@ private:
|
|||||||
if (InputService::getInstance().isMouseButtonDown(MOUSE_BUTTON_LEFT) && GetTime() - prevShot > firingRate && groundCollision)
|
if (InputService::getInstance().isMouseButtonDown(MOUSE_BUTTON_LEFT) && GetTime() - prevShot > firingRate && groundCollision)
|
||||||
{
|
{
|
||||||
prevShot = GetTime();
|
prevShot = GetTime();
|
||||||
if (ammo == 0) {
|
if (ammo == 0 || (GameService::getInstance().getMouseWorldPos().x > (this->texture.getPosition().x - this->gunLeft.getSize().x/2.0f) && spriteAnimation.y == Left) ||
|
||||||
|
(GameService::getInstance().getMouseWorldPos().x < (this->texture.getPosition().x + this->texture.getSize().x + gunLeft.getSize().x/2.0f) && spriteAnimation.y == Right))
|
||||||
|
{
|
||||||
// Play empty gun sound
|
// Play empty gun sound
|
||||||
|
AssetService::getInstance().playSound(ESound::NO_AMMO);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Play shooting sound
|
// Play shooting sound
|
||||||
|
AssetService::getInstance().playSound(ESound::SHOOT);
|
||||||
ammo--;
|
ammo--;
|
||||||
Vector2 bulletStartLocation = {this->texture.getPosition().x + 10, this->texture.getPosition().y + 10};
|
|
||||||
|
|
||||||
|
Vector2 bulletStartLocation = {this->texture.getPosition().x + 10, this->texture.getPosition().y + 10};
|
||||||
Vector2 mouseWorldPos = GameService::getInstance().getMouseWorldPos();
|
Vector2 mouseWorldPos = GameService::getInstance().getMouseWorldPos();
|
||||||
|
|
||||||
if (spriteAnimation.y == Left)
|
if (spriteAnimation.y == Left)
|
||||||
@@ -353,7 +374,7 @@ private:
|
|||||||
if (spriteAnimation.y == Right)
|
if (spriteAnimation.y == Right)
|
||||||
{
|
{
|
||||||
bulletStartLocation.y = this->texture.getPosition().y + 10;
|
bulletStartLocation.y = this->texture.getPosition().y + 10;
|
||||||
bulletStartLocation.x = this->texture.getPosition().x + 37;
|
bulletStartLocation.x = this->texture.getPosition().x + 22;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mouseWorldPos.x > this->texture.getPosition().x + (this->gunLeft.getSize().x) && spriteAnimation.y == Right ||
|
if (mouseWorldPos.x > this->texture.getPosition().x + (this->gunLeft.getSize().x) && spriteAnimation.y == Right ||
|
||||||
|
|||||||
@@ -0,0 +1,17 @@
|
|||||||
|
#ifndef ESOUND_H
|
||||||
|
#define ESOUND_H
|
||||||
|
|
||||||
|
enum class ESound {
|
||||||
|
SHOOT,
|
||||||
|
NO_AMMO,
|
||||||
|
CRATE_BREAK,
|
||||||
|
JELLY_FREED,
|
||||||
|
HEAL_PICKUP,
|
||||||
|
AMMO_PICKUP,
|
||||||
|
POWERUP,
|
||||||
|
PLAYER_DAMAGE,
|
||||||
|
ENEMY_DEFEATED,
|
||||||
|
VICTORY
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -10,6 +10,7 @@
|
|||||||
#include "enums/EBackground.h"
|
#include "enums/EBackground.h"
|
||||||
#include "enums/EMap.h"
|
#include "enums/EMap.h"
|
||||||
#include "enums/ESprite.h"
|
#include "enums/ESprite.h"
|
||||||
|
#include "enums/ESound.h"
|
||||||
#include "services/Service.h"
|
#include "services/Service.h"
|
||||||
|
|
||||||
class AssetService: public Service<AssetService>
|
class AssetService: public Service<AssetService>
|
||||||
@@ -32,6 +33,10 @@ public:
|
|||||||
return this->sprites[sprite];
|
return this->sprites[sprite];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void playSound(ESound sound) {
|
||||||
|
PlaySound(sounds[sound]);
|
||||||
|
}
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
AssetService();
|
AssetService();
|
||||||
|
|
||||||
@@ -41,7 +46,7 @@ private:
|
|||||||
|
|
||||||
std::string assetDir;
|
std::string assetDir;
|
||||||
std::unordered_map<EFont, std::string> fonts;
|
std::unordered_map<EFont, std::string> fonts;
|
||||||
std::vector<Sound> sounds;
|
std::unordered_map<ESound, Sound> sounds;
|
||||||
std::unordered_map<EMusic, Music> music;
|
std::unordered_map<EMusic, Music> music;
|
||||||
std::unordered_map<EBackground, Texture2D> backgrounds;
|
std::unordered_map<EBackground, Texture2D> backgrounds;
|
||||||
std::unordered_map<EMap, std::string> maps;
|
std::unordered_map<EMap, std::string> maps;
|
||||||
|
|||||||
@@ -0,0 +1,184 @@
|
|||||||
|
#ifndef COLLECTABLE_SERVICE_H
|
||||||
|
#define COLLECTABLE_SERVICE_H
|
||||||
|
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "services/Service.h"
|
||||||
|
#include "services/MapService.h"
|
||||||
|
#include "entities/Vector2i.h"
|
||||||
|
#include "entities/Crate.h"
|
||||||
|
#include "entities/PBullet.h"
|
||||||
|
#include <vector>
|
||||||
|
|
||||||
|
class CollectableService : public Service<CollectableService>
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
void initCollectables()
|
||||||
|
{
|
||||||
|
initCrates();
|
||||||
|
}
|
||||||
|
|
||||||
|
void collectableLogic()
|
||||||
|
{
|
||||||
|
crateLogic();
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawCollectables()
|
||||||
|
{
|
||||||
|
drawCrates();
|
||||||
|
}
|
||||||
|
|
||||||
|
// void checkCratesForCollision(PBullet bullet)
|
||||||
|
// {
|
||||||
|
// for (auto it = crates.begin(); it != crates.end();)
|
||||||
|
// {
|
||||||
|
// auto &crate = *it;
|
||||||
|
// // if (*it % 2 == 0) {
|
||||||
|
// if (crate.bulletCollision(bullet))
|
||||||
|
// {
|
||||||
|
// Vector2 pos = crate.getObject().getPosition();
|
||||||
|
// Vector2i tilePos = Vector2i(pos.x / MapService::getInstance().getMap().getTileSize(), pos.y / MapService::getInstance().getMap().getTileSize());
|
||||||
|
// MapService::getInstance().getMap().updateColmapTile(tilePos, false);
|
||||||
|
// it = crates.erase(it); // erase returns the next iterator
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// ++it;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
std::vector<Crate>& getCrates() {
|
||||||
|
return this->crates;
|
||||||
|
}
|
||||||
|
|
||||||
|
private:
|
||||||
|
void initCrates()
|
||||||
|
{
|
||||||
|
crates.clear();
|
||||||
|
Vector2 location;
|
||||||
|
int tileSize = MapService::getInstance().getMap().getTileSize();
|
||||||
|
for (int i = 0; i < 3; i++)
|
||||||
|
{
|
||||||
|
crates.push_back(Crate());
|
||||||
|
// crateLocation.push_back(location);
|
||||||
|
}
|
||||||
|
crates[0].getObject().setPosition({38.0f * tileSize, 9.0f * tileSize});
|
||||||
|
crates[1].getObject().setPosition({41.0f * tileSize, 5.0f * tileSize});
|
||||||
|
crates[2].getObject().setPosition({68.0f * tileSize, 4.0f * tileSize});
|
||||||
|
|
||||||
|
for (int i = 0; i < crates.size(); i++)
|
||||||
|
{
|
||||||
|
Vector2i crateTilePos = Vector2i(crates[i].getObject().getPosition().x / tileSize, crates[i].getObject().getPosition().y / tileSize);
|
||||||
|
MapService::getInstance().getMap().updateColmapTile(crateTilePos, true);
|
||||||
|
}
|
||||||
|
// crates[0].y = 9 * tileSize;
|
||||||
|
|
||||||
|
// crateLocation[1].x = 41 * tileSize;
|
||||||
|
// crateLocation[1].y = 5 * tileSize;
|
||||||
|
|
||||||
|
// crateLocation[2].x = 68 * tileSize;
|
||||||
|
// crateLocation[2].y = 4 * tileSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
void initJellies()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void crateLogic()
|
||||||
|
{
|
||||||
|
for (auto it = crates.begin(); it != crates.end();)
|
||||||
|
{
|
||||||
|
auto &crate = *it;
|
||||||
|
/**
|
||||||
|
* If the crate has been hit:
|
||||||
|
* 1. Remove the collision tile from the collision map
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
if (crate.hasBeenHit())
|
||||||
|
{
|
||||||
|
Vector2 pos = crate.getObject().getPosition();
|
||||||
|
Vector2i tilePos = Vector2i(pos.x / MapService::getInstance().getMap().getTileSize(), pos.y / MapService::getInstance().getMap().getTileSize());
|
||||||
|
MapService::getInstance().getMap().updateColmapTile(tilePos, false);
|
||||||
|
it = crates.erase(it);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
++it;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// void destroyCrate(int index) {
|
||||||
|
// Vector2 pos = crates[index].getObject().getPosition();
|
||||||
|
// Vector2i tilePos = Vector2i(pos.x/MapService::getInstance().getMap().getTileSize(), pos.y/MapService::getInstance().getMap().getTileSize());
|
||||||
|
// MapService::getInstance().getMap().updateColmapTile(tilePos, false);
|
||||||
|
// crates.erase(crates.begin() + index);
|
||||||
|
// }
|
||||||
|
|
||||||
|
// void checkCratesForCollision(PBullet bullet)
|
||||||
|
// {
|
||||||
|
// for (auto it = crates.begin(); it != crates.end();)
|
||||||
|
// {
|
||||||
|
// auto &crate = *it;
|
||||||
|
// // if (*it % 2 == 0) {
|
||||||
|
// if (crate.bulletCollision(bullet))
|
||||||
|
// {
|
||||||
|
// Vector2 pos = crate.getObject().getPosition();
|
||||||
|
// Vector2i tilePos = Vector2i(pos.x / MapService::getInstance().getMap().getTileSize(), pos.y / MapService::getInstance().getMap().getTileSize());
|
||||||
|
// MapService::getInstance().getMap().updateColmapTile(tilePos, false);
|
||||||
|
// it = crates.erase(it); // erase returns the next iterator
|
||||||
|
// }
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// ++it;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
|
||||||
|
void jellyLogic()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawCrates()
|
||||||
|
{
|
||||||
|
for (int i = 0; i < crates.size(); i++)
|
||||||
|
{
|
||||||
|
crates[i].draw();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawJellies()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawHudJellies()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawAmmoPacks()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
void drawHealthpacks()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
// sf::Text jelliesFreed; // Holds the text that shows how many jellies are freed
|
||||||
|
// sf::Font jelliesFreedFont; // Holds the font used for the text of the display
|
||||||
|
|
||||||
|
// sf::Sprite jelliesFreedSprite; // Holds the sprite of the jelly in the top right corner
|
||||||
|
|
||||||
|
// Vector2i jellyDisplayLocation; // Holds the location where the amount of jellies freed are displayed
|
||||||
|
std::vector<Crate> crates;
|
||||||
|
// std::vector<sf::Sprite> crateSprite; // Holds the sprites of the crates
|
||||||
|
// std::vector<sf::Sprite> jellySprite; // Holds the sprites of the jellies inside the crates
|
||||||
|
// std::vector<Vector2> crateLocation; // Holds the locations of the crates/jellies
|
||||||
|
// std::vector<Vector2> velocity; // Makes sure the jellies jump when the crate is destroyed
|
||||||
|
// std::vector<bool> collision; // Keeps track of whether or not the player has collided with a crate
|
||||||
|
// std::vector<bool> crateDestroyed; // Keeps track of whether or not a crate has been destroyed
|
||||||
|
|
||||||
|
// unsigned int totalAmntCrates; // Holds the total amount of crates
|
||||||
|
// unsigned int amntCratesDestroyed; // Holds the amount of crates that have been destroyed
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
@@ -47,6 +47,11 @@ public:
|
|||||||
Vector2 mouseWorldPos = {GetMousePosition().x + camera.target.x - camera.offset.x, GetMousePosition().y};
|
Vector2 mouseWorldPos = {GetMousePosition().x + camera.target.x - camera.offset.x, GetMousePosition().y};
|
||||||
return mouseWorldPos;
|
return mouseWorldPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Vector2 toWorldPos(Vector2i pixelPos) {
|
||||||
|
Vector2 worldPos = {(float)pixelPos.x + camera.target.x - camera.offset.x, (float)pixelPos.y};
|
||||||
|
return worldPos;
|
||||||
|
}
|
||||||
// void setGame(Game game) {
|
// void setGame(Game game) {
|
||||||
// this->game = game;
|
// this->game = game;
|
||||||
// }
|
// }
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
clear
|
clear
|
||||||
# g++ src/main.cpp -o dist/jelly_rescue -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
# g++ src/main.cpp -o dist/jelly_rescue -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
||||||
g++ $(find src/ -name "*.cpp") -o dist/jelly_rescue -I./include -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
# g++ -std=c++20 $(find src/ -name "*.cpp") -o dist/jelly_rescue -I./include -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
||||||
|
g++ -std=c++20 -g -O0 $(find src/ -name "*.cpp") -o dist/jelly_rescue -I./include -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
||||||
|
|
||||||
# g++ src/main.cpp -o dist/jelly_rescue -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
# g++ src/main.cpp -o dist/jelly_rescue -L$LD_LIBRARY_PATH -lraylib -lGL -lm -lpthread -ldl -lrt -lX11
|
||||||
./dist/jelly_rescue
|
gdb dist/jelly_rescue
|
||||||
|
|||||||
@@ -20,6 +20,13 @@ void AssetService::setAssets()
|
|||||||
music[EMusic::GAME_OVER] = loadMusic("Audio/Music/gameOverTheme_2.ogg", false);
|
music[EMusic::GAME_OVER] = loadMusic("Audio/Music/gameOverTheme_2.ogg", false);
|
||||||
/** Todo: set volume */
|
/** Todo: set volume */
|
||||||
|
|
||||||
|
sounds[ESound::SHOOT] = loadSound("Audio/Sounds/gunShot.wav");
|
||||||
|
SetSoundVolume(sounds[ESound::SHOOT], 0.4f);
|
||||||
|
sounds[ESound::NO_AMMO] = loadSound("Audio/Sounds/outOfAmmo.wav");
|
||||||
|
sounds[ESound::CRATE_BREAK] = loadSound("Audio/Sounds/crateBreak.wav");
|
||||||
|
SetSoundVolume(sounds[ESound::CRATE_BREAK], 1.0f);
|
||||||
|
sounds[ESound::JELLY_FREED] = loadSound("Audio/Sounds/jellyFreed.wav");
|
||||||
|
|
||||||
backgrounds[EBackground::TUTORIAL] = loadTexture("Textures/TutorialBackground2.png");
|
backgrounds[EBackground::TUTORIAL] = loadTexture("Textures/TutorialBackground2.png");
|
||||||
backgrounds[EBackground::GAME1] = loadTexture("Textures/GameBackground_1.png");
|
backgrounds[EBackground::GAME1] = loadTexture("Textures/GameBackground_1.png");
|
||||||
backgrounds[EBackground::GAME2] = loadTexture("Textures/GameBackground_2.jpg");
|
backgrounds[EBackground::GAME2] = loadTexture("Textures/GameBackground_2.jpg");
|
||||||
|
|||||||
@@ -1,13 +1,13 @@
|
|||||||
#include "services/StateService.h"
|
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
|
#include "services/StateService.h"
|
||||||
|
#include "services/AudioService.h"
|
||||||
|
#include "services/InputService.h"
|
||||||
#include "screens/TitleScreen.h"
|
#include "screens/TitleScreen.h"
|
||||||
#include "screens/MainScreen.h"
|
#include "screens/MainScreen.h"
|
||||||
#include "screens/TutorialScreen.h"
|
#include "screens/TutorialScreen.h"
|
||||||
#include "screens/GameScreen.h"
|
#include "screens/GameScreen.h"
|
||||||
#include "screens/GameOverScreen.h"
|
#include "screens/GameOverScreen.h"
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include "services/AudioService.h"
|
|
||||||
#include "services/InputService.h"
|
|
||||||
|
|
||||||
void StateService::setScreen(EScreen state)
|
void StateService::setScreen(EScreen state)
|
||||||
{
|
{
|
||||||
@@ -45,7 +45,7 @@ void StateService::startGame()
|
|||||||
{
|
{
|
||||||
// if(!instance)
|
// if(!instance)
|
||||||
// return;
|
// return;
|
||||||
// InitAudioDevice();
|
InitAudioDevice();
|
||||||
// InitWindow(640,544, "Jelly Rescue");
|
// InitWindow(640,544, "Jelly Rescue");
|
||||||
InitWindow(screenSize.x, screenSize.y, "Jelly Rescue");
|
InitWindow(screenSize.x, screenSize.y, "Jelly Rescue");
|
||||||
SetTargetFPS(45);
|
SetTargetFPS(45);
|
||||||
@@ -75,7 +75,7 @@ void StateService::startGame()
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
CloseWindow();
|
CloseWindow();
|
||||||
// CloseAudioDevice();
|
CloseAudioDevice();
|
||||||
}
|
}
|
||||||
|
|
||||||
void StateService::handleMusic()
|
void StateService::handleMusic()
|
||||||
|
|||||||
Reference in New Issue
Block a user