fixed bg
This commit is contained in:
@@ -28,5 +28,5 @@ void Entity::Update(float deltatime) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void Entity::Draw() {
|
void Entity::Draw() {
|
||||||
DrawTextureEx(entityTextures.GetTexture(spriteid), raylib::Vector2(rect.x, rect.y), 0, 0, WHITE);
|
DrawTextureEx(entityTextures.GetTexture(spriteid), raylib::Vector2(rect.x, rect.y), 0, 1, WHITE);
|
||||||
}
|
}
|
||||||
|
|||||||
+7
-15
@@ -1,10 +1,8 @@
|
|||||||
#include "../include/raylib-cpp.hpp"
|
#include "../include/raylib-cpp.hpp"
|
||||||
#include "entities/entitybase.hpp"
|
#include "entities/entitybase.hpp"
|
||||||
#include "render/textures.hpp"
|
#include "render/textures.hpp"
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
void PlayerController(Entity &e, float deltatime) {
|
void PlayerController(Entity &e, float deltatime) {
|
||||||
raylib::Vector2 velocity = {0,0};
|
|
||||||
raylib::Vector2 acceleration = {0,0};
|
raylib::Vector2 acceleration = {0,0};
|
||||||
if (IsKeyDown(KEY_W)) acceleration.y--;
|
if (IsKeyDown(KEY_W)) acceleration.y--;
|
||||||
if (IsKeyDown(KEY_A)) acceleration.x--;
|
if (IsKeyDown(KEY_A)) acceleration.x--;
|
||||||
@@ -13,28 +11,23 @@ void PlayerController(Entity &e, float deltatime) {
|
|||||||
|
|
||||||
acceleration.Normalize();
|
acceleration.Normalize();
|
||||||
|
|
||||||
e.velocity.x += acceleration.x * 200 * deltatime;
|
e.rect.x += acceleration.x * 100 * deltatime;
|
||||||
e.velocity.y += acceleration.y * 200 * deltatime;
|
|
||||||
|
|
||||||
e.velocity.x *= 0.98;
|
e.rect.y += acceleration.y * 100 * deltatime;
|
||||||
e.velocity.y *= 0.98;
|
|
||||||
|
|
||||||
e.rect.x += e.velocity.x * deltatime;
|
|
||||||
|
|
||||||
e.rect.y += e.velocity.y * deltatime;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
int screenWidth = 1920;
|
int screenWidth = 1920;
|
||||||
int screenHeight = 1080;
|
int screenHeight = 1080;
|
||||||
|
|
||||||
|
|
||||||
raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");
|
raylib::Window window(screenWidth, screenHeight, "raylib-cpp - basic window");
|
||||||
|
|
||||||
SetTargetFPS(60);
|
SetTargetFPS(60);
|
||||||
|
|
||||||
GenDefaultTexture();
|
GenDefaultTexture();
|
||||||
|
|
||||||
raylib::Rectangle playerrect{screenWidth / 2.0f, screenHeight / 2.0f,64.0f,64.0f};
|
raylib::Rectangle playerrect{screenWidth / 2.0f, screenHeight / 2.0f,64,64};
|
||||||
Entity player{1, playerrect, "MainPlayer", 100, 100};
|
Entity player{1, playerrect, "MainPlayer", 100, 100};
|
||||||
player.controller = PlayerController;
|
player.controller = PlayerController;
|
||||||
player.spriteid = 1;
|
player.spriteid = 1;
|
||||||
@@ -66,7 +59,6 @@ int main() {
|
|||||||
DrawText("Middle", 190, 200, 20, WHITE);
|
DrawText("Middle", 190, 200, 20, WHITE);
|
||||||
|
|
||||||
Texture bg = tileTextures.GetTexture(1);
|
Texture bg = tileTextures.GetTexture(1);
|
||||||
std::cout << bg.height;
|
|
||||||
|
|
||||||
// Infinite Background
|
// Infinite Background
|
||||||
int bh = bg.height;
|
int bh = bg.height;
|
||||||
@@ -78,8 +70,8 @@ int main() {
|
|||||||
for (int j = -1; j <= GetScreenHeight() / bh + 1; j++) {
|
for (int j = -1; j <= GetScreenHeight() / bh + 1; j++) {
|
||||||
DrawTexture(
|
DrawTexture(
|
||||||
bg,
|
bg,
|
||||||
-offsetX + i * bw,
|
camera.target.x - offsetX - screenWidth / 2.0f + i * bw,
|
||||||
-offsetY + j * bh,
|
camera.target.y - offsetY - screenHeight / 2.0f + j * bh,
|
||||||
WHITE
|
WHITE
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user