[Added] Jellies, healthpacks, ammopacks, powerups, [Updated] Gun rotation
This commit is contained in:
@@ -0,0 +1,58 @@
|
||||
#ifndef POWERUP_H
|
||||
#define POWERUP_H
|
||||
|
||||
#include "raylib.h"
|
||||
#include "services/AssetService.h"
|
||||
#include "entities/TextureWrapper.h"
|
||||
|
||||
class Powerup {
|
||||
public:
|
||||
Powerup() {
|
||||
this->object = TextureWrapper(AssetService::getInstance().getSprite(ESprite::POWERUP),{50,55});
|
||||
}
|
||||
void logic(){
|
||||
animate();
|
||||
}
|
||||
|
||||
void draw() {
|
||||
DrawTextureRec(object.getTexture(), object.getSourceRect(), object.getPosition(), WHITE);
|
||||
}
|
||||
|
||||
float getExtraJumpPower() {
|
||||
return this->extraJumpPower;
|
||||
}
|
||||
|
||||
void setPickedUp(bool pickedUp) {
|
||||
this->pickedUp = pickedUp;
|
||||
}
|
||||
|
||||
bool hasBeenPickedUp() {
|
||||
return this->pickedUp;
|
||||
}
|
||||
|
||||
TextureWrapper& getObject() {
|
||||
return this->object;
|
||||
}
|
||||
|
||||
private:
|
||||
TextureWrapper object;
|
||||
float extraJumpPower = 2.0f; // Jump power gained by grabbing the powerup
|
||||
bool pickedUp = false; // When the player has picked up the pack
|
||||
float animationDelay = 0.08f; // How long to wait in between animation frames (in seconds)
|
||||
double lastFrame; // Time since the last frame
|
||||
u_int8_t currentFrame = 0; // Current frame of the animation
|
||||
u_int8_t amountOfFrames = 8; // Total amount of animation frames
|
||||
|
||||
void animate() {
|
||||
if(GetTime() - lastFrame > animationDelay) {
|
||||
currentFrame ++;
|
||||
currentFrame %= amountOfFrames;
|
||||
|
||||
object.setSourceRect({(float)currentFrame * 81 + 16, 10,object.getSize().x, object.getSize().y});
|
||||
lastFrame = GetTime();
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
Reference in New Issue
Block a user