clouds
This commit is contained in:
@@ -2,14 +2,17 @@
|
||||
#include <iostream>
|
||||
#include "resourceManager.h"
|
||||
|
||||
class tileSet {
|
||||
class tileSet
|
||||
{
|
||||
Texture tileSheet;
|
||||
glm::ivec2 dims;
|
||||
public:
|
||||
tileSet(const Texture& texture, glm::vec2 tileDims)
|
||||
:tileSheet(texture), dims(tileDims){}
|
||||
|
||||
glm::vec4 getUVs(int index) {
|
||||
public:
|
||||
tileSet(const Texture &texture, glm::ivec2 tileDims)
|
||||
: tileSheet(texture), dims(tileDims) {}
|
||||
|
||||
glm::vec4 getUVs(int index)
|
||||
{
|
||||
int tileX = index % dims.x;
|
||||
int tileY = index / dims.x;
|
||||
|
||||
@@ -20,4 +23,17 @@ public:
|
||||
UV.w = UV.y - 1.0f / dims.y;
|
||||
return UV;
|
||||
}
|
||||
glm::vec4 getUVsExtended(int index, int lengthX, int lengthY)
|
||||
{
|
||||
int tileX = index % dims.x;
|
||||
int tileY = index / dims.x;
|
||||
int secondTileX = lengthX % dims.x;
|
||||
std::cout << "secondTileX: " << secondTileX << "\n";
|
||||
glm::vec4 UV;
|
||||
UV.x = tileX / (float)dims.x;
|
||||
UV.y = tileY / (float)dims.y;
|
||||
UV.z = UV.x + (float)secondTileX / dims.x;
|
||||
UV.w = UV.y - (float)lengthY / dims.y;
|
||||
return UV;
|
||||
}
|
||||
};
|
||||
39
include/background.h
Normal file
39
include/background.h
Normal file
@@ -0,0 +1,39 @@
|
||||
#pragma once
|
||||
#include "spriteRenderer.h"
|
||||
#include "resourceManager.h"
|
||||
#include "animationManager.h"
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <GLFW/glfw3.h>
|
||||
#include <glm/glm.hpp>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
class Cloud
|
||||
{
|
||||
float speed;
|
||||
glm::vec2 pos, size;
|
||||
glm::vec4 spriteUVs;
|
||||
|
||||
GLuint quadVAO, VBO, EBO;
|
||||
Texture Sprite = ResourceManager::LoadTexture("../art/background/CloudsBDayJullietje.png", "cloudSheet");
|
||||
;
|
||||
tileSet spriteSheet = tileSet(Sprite, glm::ivec2(20, 20));
|
||||
|
||||
public:
|
||||
Cloud(float speed, glm::vec2 pos, glm::vec2 size, int cloudIndex);
|
||||
|
||||
void drawCloud(SpriteRenderer &renderer, float dt);
|
||||
};
|
||||
|
||||
class Background
|
||||
{
|
||||
private:
|
||||
Cloud *cloud = nullptr;
|
||||
std::vector<Cloud *> clouds;
|
||||
|
||||
public:
|
||||
Background();
|
||||
void drawBackground(SpriteRenderer &renderer, float dt);
|
||||
void drawClouds(SpriteRenderer &renderer);
|
||||
};
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
Texture Sprite;
|
||||
glm::vec4 spriteUVs;
|
||||
|
||||
tileSet* spriteSheet = new tileSet(Sprite, glm::vec2(8, 3));
|
||||
tileSet* spriteSheet = new tileSet(Sprite, glm::ivec2(8, 3));
|
||||
|
||||
int state;
|
||||
|
||||
|
||||
@@ -16,11 +16,14 @@
|
||||
#include "enemy.h"
|
||||
#include "object.h"
|
||||
#include "world.h"
|
||||
#include "background.h"
|
||||
|
||||
#include <cute_headers-master/cute_c2.h>
|
||||
#include <cute_headers-master/cute_gl.h>
|
||||
|
||||
#include <glad/glad.h>
|
||||
#include <glad/glad.h>
|
||||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/matrix_transform.hpp>
|
||||
#include <glm/gtc/type_ptr.hpp>
|
||||
@@ -28,10 +31,13 @@ class Game {
|
||||
private:
|
||||
float x = 0;
|
||||
|
||||
std::vector<Object*> objects;
|
||||
|
||||
SpriteRenderer* renderer = nullptr;
|
||||
Player* player = nullptr;
|
||||
World* world = nullptr;
|
||||
Enemy* enemy = nullptr;
|
||||
Background* background = nullptr;
|
||||
//Object* dirtBlock = nullptr;
|
||||
//Object* dirtBlock1 = nullptr;
|
||||
//position
|
||||
@@ -52,7 +58,7 @@ class Game {
|
||||
|
||||
//Gameloop
|
||||
void handleEvents(float dt);
|
||||
void render();
|
||||
void render(float dt);
|
||||
//getset
|
||||
GLFWwindow* getWindow();
|
||||
};
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
|
||||
#include "texture.h"
|
||||
#include "shader.h"
|
||||
#include "resourceManager.h"
|
||||
|
||||
|
||||
class SpriteRenderer
|
||||
|
||||
@@ -16,15 +16,15 @@ class Object
|
||||
public:
|
||||
GLfloat vertices[16];
|
||||
|
||||
glm::vec2 Position, Size;
|
||||
float Rotation = 0.0f;
|
||||
glm::vec2 position, size;
|
||||
float rotation = 0.0f;
|
||||
int blockType;
|
||||
Texture Sprite;
|
||||
Texture sprite;
|
||||
c2AABB objectBody;
|
||||
GLuint quadVAO, VBO, EBO;
|
||||
|
||||
glm::vec4 spriteUVs;
|
||||
tileSet* spriteSheet = new tileSet(Sprite, glm::vec2(10, 10));
|
||||
tileSet* spriteSheet = new tileSet(sprite, glm::ivec2(10, 10));
|
||||
|
||||
Object(Texture sprite, glm::vec2 pos, glm::vec2 size, int blockType = 2);
|
||||
~Object();
|
||||
|
||||
@@ -27,7 +27,7 @@ public:
|
||||
|
||||
glm::vec2 Position, Size;
|
||||
float gravity = 1600.0f, maxGravity = 2000.0f, hAcceleration = 1600.0f, hDeacceleration = 800.0f, maxSpeed = 300.0f,
|
||||
jumpStrength = -1100.0f, maxWalkingSpeed = 300.0f ,maxRunningSpeed = 450.0f;
|
||||
jumpStrength = -800.0f, maxWalkingSpeed = 300.0f ,maxRunningSpeed = 450.0f;
|
||||
float hSpeed = 0.0f;
|
||||
float vSpeed = 0.0f;
|
||||
//aniamtions
|
||||
@@ -39,7 +39,7 @@ public:
|
||||
Texture Sprite;
|
||||
glm::vec4 spriteUVs;
|
||||
|
||||
tileSet* spriteSheet = new tileSet(Sprite, glm::vec2(10,12));
|
||||
tileSet* spriteSheet = new tileSet(Sprite, glm::ivec2(10,12));
|
||||
|
||||
int state;
|
||||
|
||||
@@ -52,5 +52,4 @@ public:
|
||||
void calcPos(float dt);
|
||||
void animSprite(float dt);
|
||||
private:
|
||||
};
|
||||
|
||||
};
|
||||
Reference in New Issue
Block a user