Pacman
This commit is contained in:
parent
c3f3466bc4
commit
5273927cb3
5 changed files with 66 additions and 24 deletions
BIN
assets/sprites/pacman.png
Normal file
BIN
assets/sprites/pacman.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 461 B |
|
|
@ -1,2 +1,5 @@
|
||||||
-Wall
|
-Wall
|
||||||
-lraylib
|
-lraylib
|
||||||
|
-lstdc++
|
||||||
|
-lm
|
||||||
|
-v
|
||||||
|
|
|
||||||
22
main.cpp
22
main.cpp
|
|
@ -1,22 +0,0 @@
|
||||||
#include <raylib.h>
|
|
||||||
|
|
||||||
int main() {
|
|
||||||
const int screen_height = 720;
|
|
||||||
const int screen_width = 1280;
|
|
||||||
|
|
||||||
InitWindow(screen_width, screen_height, "Test game");
|
|
||||||
|
|
||||||
SetTargetFPS(60);
|
|
||||||
|
|
||||||
while (WindowShouldClose() == false) {
|
|
||||||
BeginDrawing();
|
|
||||||
|
|
||||||
ClearBackground(RAYWHITE);
|
|
||||||
|
|
||||||
DrawText("Congrats to me, I created first window!", 190, 200, 20, LIGHTGRAY);
|
|
||||||
|
|
||||||
EndDrawing();
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
5
makefile
5
makefile
|
|
@ -1,8 +1,9 @@
|
||||||
CFLAGS=$(shell cat compiler_flags.txt)
|
CFLAGS=$(shell cat compiler_flags.txt)
|
||||||
|
|
||||||
build/raylib-test-linux.x86_64 : main.cpp
|
build/raylib-test-linux.x86_64 : src/main.cpp
|
||||||
mkdir -p build
|
mkdir -p build
|
||||||
clang main.cpp $(CFLAGS) -o build/raylib-test-linux.x86_64
|
clang src/main.cpp $(CFLAGS) -o build/raylib-test-linux.x86_64
|
||||||
|
|
||||||
|
|
||||||
clean :
|
clean :
|
||||||
rm -r build/*
|
rm -r build/*
|
||||||
|
|
|
||||||
60
src/main.cpp
Normal file
60
src/main.cpp
Normal file
|
|
@ -0,0 +1,60 @@
|
||||||
|
#include <raylib.h>
|
||||||
|
#include <cmath>
|
||||||
|
#include <raymath.h>
|
||||||
|
|
||||||
|
class Pacman {
|
||||||
|
const int speed = 16;
|
||||||
|
private:
|
||||||
|
Texture2D texture;
|
||||||
|
Vector2 position;
|
||||||
|
int facing;
|
||||||
|
|
||||||
|
Rectangle getTextureRect(){
|
||||||
|
Rectangle result;
|
||||||
|
result.x = 0;
|
||||||
|
result.y = facing;
|
||||||
|
result.height = 16;
|
||||||
|
result.width = 16;
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
public:
|
||||||
|
Pacman() {
|
||||||
|
this->texture = LoadTexture("assets/sprites/pacman.png");
|
||||||
|
this->facing = 0;
|
||||||
|
}
|
||||||
|
~Pacman() {
|
||||||
|
UnloadTexture(this->texture);
|
||||||
|
}
|
||||||
|
|
||||||
|
void process() {
|
||||||
|
float delta = GetFrameTime();
|
||||||
|
|
||||||
|
// Movement in direction
|
||||||
|
double angle = PI/2.0*facing;
|
||||||
|
Vector2 direction = {(float)(cos(angle)),(float)(sin(angle))};
|
||||||
|
this->position = Vector2Add(this->position,Vector2Scale(direction, delta * (float)speed));
|
||||||
|
|
||||||
|
DrawTextureRec(this->texture, this->getTextureRect(), this->position, WHITE);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
int main() {
|
||||||
|
const int screen_height = 320;
|
||||||
|
const int screen_width = 320;
|
||||||
|
|
||||||
|
InitWindow(screen_width, screen_height, "Test game");
|
||||||
|
|
||||||
|
SetTargetFPS(60);
|
||||||
|
|
||||||
|
Pacman pacman;
|
||||||
|
|
||||||
|
while (WindowShouldClose() == false) {
|
||||||
|
BeginDrawing();
|
||||||
|
|
||||||
|
pacman.process();
|
||||||
|
|
||||||
|
EndDrawing();
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue