67 afișări Istudor Denis Ionut (Denis________) 08 iun
www.pbinfo.ro
Etichete: nicio etichetă

#include “raylib.h”
#include

#pragma region assets
int player_sprite[64*3][36*3] = {{0,0,1,0,0}, {0,1,1,1,0}, {1,1,2,1,1}, {1,1,2,1,1}, {0,3,0,3,0}};
Color player_colors7832 = {(Color){ 0, 0, 0, 0 },GRAY,BLUE,RED};
int gun_sprite[64*3][36*3] = {{0,3,0,0,0}, {0,3,2,0,0}, {0,3,2,0,0}, {0,3,1,0,0}, {0,0,1,1,0}};
Color gun_colors7832 = {(Color){ 0, 0, 0, 0 },(Color){ 102, 47, 49, 255 },(Color){ 94, 94, 94, 255 },(Color){ 105, 106, 106, 255 }};
#pragma endregion assets

enum{ //TODO: fix the code
None=0,
Track,
Forward
};
const int Width = 64*3;
const int Height = 36*3;
const int PixelSize = 4;
Color Render[Width][Height];

class Rendered{ public: Vector2 position; int width; int height; int sprite[64*3][36*3]; //TODO: i forgot and accidentally removed all color ): done hopefully Color colors7832; int color_count;

void DrawPixel(Vector2 lposition, Color color){ int x = int(lposition.x); int y = int(lposition.y); if(x < Width && y < Height && x >= 0 && y >= 0){ Render[x][y] = color; } } void DrawSprite(Vector2 parentPos = {0,0}){ for(int i = 0;i7832, int temp_color_count){ for(int i = 0;i<width;i++) for(int j = 0;j<height;j++) sprite[j][i] = temp_sprite[i][j]; for(int i = 0;i<temp_color_count;i++){ colors[i] = temp_color[i]; } } void setSize(Vector2 temp_size){ width = temp_size.x; height = temp_size.y; } void setPos(Vector2 temp_position){ position = temp_position; } Rendered(Vector2 tposition, Vector2 tsprite_size, int tsprite[64*3][36*3], Color tcolor7832, int tcolor_count){ setPos(tposition); setSize(tsprite_size); initSprite(tsprite,tcolor,tcolor_count); } Rendered(){}

};

class Movable : public Rendered{ //TODO: properly do classes now that i have a pdf of them
public: int speed; int move_type; bool bounded; std::list children;

Vector2 direction; void setSpeed(int temp_speed){speed = temp_speed;} void setMoveType(int temp_move_type){move_type=temp_move_type;} void setBounded(bool temp_bounded){bounded = temp_bounded;} void addChild(Movable child){children.push_back(child);} Movable(Vector2 tposition, Vector2 tsprite_size, int tsprite[64*3][36*3], Color tcolor7832, int tcolor_count, int tspeed, int tmove_type, bool tbounded) : Rendered(tposition,tsprite_size,tsprite,tcolor,tcolor_count){ setSpeed(tspeed); setBounded(tbounded); setMoveType(tmove_type); } Movable():Rendered(){} void moveMovable(){ if(position.x < Width && position.y < Height && position.x >= 0 && position.y >= 0) bounded = bounded; else bounded = false; if(!bounded || (position.x + direction.x*speed < Width && position.x + direction.x*speed >= 0)) position.x += direction.x*speed; if(!bounded || (position.y + direction.y*speed < Height && position.y + direction.y*speed >= 0)) position.y += direction.y*speed; direction = {0,0}; } //for(Entity e : children) DrawEntity(e,position); }; class Entity : public Movable{ public: int hp; int damage; Entity(Vector2 tposition, Vector2 tsprite_size, int tsprite[64*3][36*3], Color tcolor7832, int tcolor_count, int tspeed, int tmove_type, bool tbounded, int thp, int tdamage) : Movable(/*tposition, tsprite_size, tsprite[64*3][36*3], tcolor7832, tcolor_count, tspeed, tmove_type, tbounded*/){ setPos(tposition); setSize(tsprite_size); initSprite(tsprite,tcolor,tcolor_count); setSpeed(tspeed); setBounded(tbounded); setMoveType(tmove_type); hp = thp; damage = tdamage; } };

//void shoot(Entity shooter, ) //TODO gun class that extends entity, bullet class, shooting system with spread, direction, speed, nr. of projectiles
//——————————————————————————————————————————
// Program main entry point
//——————————————————————————————————————————
int main(void)
{ // Initialization //———————————————————————————————————————————

std::list Enemies; InitWindow(Width*PixelSize, Height*PixelSize, “dodge stuff”); Entity Player(Vector2{ (float)Width/2, (float)Height/2 },Vector2{5,5}, player_sprite, player_colors, 4, 2,0,true,5,0); /*Player.colors1 = GRAY; Player.colors2 = BLUE; Player.colors3 = RED;*/ //Player.speed = 2; //initSprite(Player,player_sprite); Entity Gun(Vector2{-3,1},Vector2{5,5},gun_sprite,gun_colors,4,2,0,false,0,5); /*Gun.color1 = gun_colors1; Gun.color2 = gun_colors2; Gun.color3 = gun_colors3; Gun.speed = 3; Gun.bounded = false; Gun.position = { -3, -1 }; initSprite(Gun,gun_sprite);*/ SetTargetFPS(60); // Set our game to run at 60 frames-per-second //——————————————————————————————————————————— // Main game loop while (!WindowShouldClose()) // Detect window close button or ESC key { // Update //————————————————————————————————————————— if (IsKeyDown(KEY_RIGHT)) Player.direction.x += 1; if (IsKeyDown(KEY_LEFT)) Player.direction.x -= 1; if (IsKeyDown(KEY_UP)) Player.direction.y -= 1; if (IsKeyDown(KEY_DOWN)) Player.direction.y += 1; Player.moveMovable(); //————————————————————————————————————————— // Draw //————————————————————————————————————————— BeginDrawing(); for(int x = 0; x < Width; x++) for(int y = 0; y<Height; y++) Render[x][y] = RAYWHITE; //for(Entity enemy : Enemies) DrawEntity(enemy); Player.DrawSprite(); Gun.DrawSprite(); for(int x = 0; x < Width; x++) for(int y = 0; y < Height; y++){ DrawRectangle(x*PixelSize,y*PixelSize,PixelSize,PixelSize,Render[x][y]); } EndDrawing(); //————————————————————————————————————————— } // De-Initialization //——————————————————————————————————————————— CloseWindow(); // Close window and OpenGL context //——————————————————————————————————————————— return 0; }

67 afișări Istudor Denis Ionut (Denis________) 08 iun
www.pbinfo.ro
Du-te sus!