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