Eiyeron Fulmincendii пре 9 година
родитељ
комит
0a820bf002

+ 2 - 2
Makefile

@@ -2,7 +2,7 @@ NAME = Pacman-Lua
 
 DEBUG = FALSE
 
-CFLAGS_COMMON = -Wall -W $(addprefix -I,$(INCLUDE) $(INCLUDE_EXT)) -MMD -MP -pipe
+CFLAGS_COMMON = -Wall -W $(addprefix -I,$(INCLUDE) $(INCLUDE_EXT)) -MMD -MP -pipe -DSFML_STATIC=1 -DSFML_USE_STATIC_STD_LIBS=1
 
 ifeq ($(DEBUG),FALSE)
 	CFLAGS_COMMON += -Ofast -flto
@@ -16,7 +16,7 @@ CPPFLAGS = $(CFLAGS_COMMON) -std=gnu++11
 
 LIBS = -lz -llua
 #LDFLAGS = -flto
-LDFLAGS = $(CFLAGS_COMMON)  -lz
+LDFLAGS = $(CFLAGS_COMMON)  -lz  -DSFML_STATIC=1 -DSFML_USE_STATIC_STD_LIBS=1
 
 SRCS_C :=
 SRCS_CPP :=

+ 11 - 0
data/clyde.lua

@@ -0,0 +1,11 @@
+clyde = {
+    t = 0,
+    init = function(self)
+    end,
+    update = function(self)
+        self.t = self.t + 1
+        if self.t %60 == 0 then
+            self.intent = math.random(0, 4)
+        end
+    end
+}

+ 11 - 0
data/inky.lua

@@ -0,0 +1,11 @@
+inky = {
+    t = 0,
+    init = function(self)
+    end,
+    update = function(self)
+        self.t = self.t + 1
+        if self.t %60 == 0 then
+            self.intent = math.random(0, 4)
+        end
+    end
+}

+ 46 - 0
data/p1.lua

@@ -0,0 +1,46 @@
+p1 = {
+    -- Pushed values to this object on update (self.xxx)
+    -- x,y (in) : top left corner of the entity
+    -- vx,vy (in) : Velocity
+    -- width (in), height : dimensions of the map<->entity hitbox
+    -- points (in) : scored points
+    -- intent (in-out) : Intended direction of the entity when it'll can.
+        -- Editing intent will impact the AI's deplacement.
+
+    -- The game structure
+    -- The map is stored as 8*8pixel tiles.
+    -- The map has a dimension of 224*248 pixels (borders included).
+    -- To push the IA to move to another direction when it can, edit self.
+    -- The game structure stores the players' and ghosts' position (in pixel) and velocity
+        -- gamestructure.p1.x
+        -- gamestructure.p2.y
+        -- gamestructure.blinky == red
+        -- gamestructure.inky == cyan
+        -- gamestructure.pinky == huh
+        -- gamestructure.clyde == orange
+
+    -- gamestate functions
+    -- Note : All of those functions needs gamestate.data as first argument
+    --  collide(gamestate.data, x,y,w,h) checks if a rectangle defined by its left corner and its dimensions collides with the walls.
+    --  get_tile(gamestate.data, x, y) returns the tile on the map with tile coordinates. Returns a tbale with a has_gum integer and is_solid boolean
+
+    init = function(self)
+    end,
+    update = function(self)
+        self.intent = math.random(0, 4)
+        local pos = self:get_tile_coords_at_center()
+    end,
+    -- This one wil just be called from update or init as such:
+    --     self:get_tile_coords_at_center
+    -- Returns a table {x =  tile_pos_y, y = tile_pos_y} or nil when the Pacman is out of bounds, so to use the variables
+    -- do something like this:
+    --     local pos = self:get_tile_coords_at_center()
+    --     print("x : "..pos.x.." y : "..pos["x"])
+    get_tile_coords_at_center = function(self)
+        if self.x < 0 or self.x > 224-16 or self.y < 0 or self.y > 248-16 then
+            return nil
+        else
+            return {x=math.floor((self.x+4)/8), y=math.floor((self.y+4)/8)}
+        end
+    end
+}

+ 11 - 0
data/pinky.lua

@@ -0,0 +1,11 @@
+pinky = {
+    t = 0,
+    init = function(self)
+    end,
+    update = function(self)
+        self.t = self.t + 1
+        if self.t %60 == 0 then
+            self.intent = math.random(0, 4)
+        end
+    end
+}

+ 1 - 1
external/luwra

@@ -1 +1 @@
-Subproject commit fe1dcdb02840464b7b67cb665b1000a83208133e
+Subproject commit 15044855f95d281747d4eb860413f2ce458adb29

+ 2 - 2
platform/windows/rules.mk

@@ -4,9 +4,9 @@ SRCS_C += $(wildcard $(windows_LOCAL_PATH)/platform/*.c)
 SRCS_CPP += $(wildcard $(windows_LOCAL_PATH)/*.cpp)
 INCLUDE += $(windows_LOCAL_PATH)/public
 
-LDFLAGS += -L/usr/lib -lstdc++ -lsfml-graphics -lsfml-window -lsfml-system -lopengl32 -lwinmm -lgdi32 -lm
+LDFLAGS += -L/usr/lib -lstdc++ -lsfml-graphics-s -lsfml-window-s -lsfml-system-s -lopengl32 -ljpeg -lwinmm -lgdi32 -lm
 
-CFLAGS_COMMON += -DTARGET_WINDOWS=1 -mwindows
+CFLAGS_COMMON += -DTARGET_WINDOWS=1 
 
 INCLUDE_EXT += /usr/include
 

+ 2 - 2
src/pacman/AIEntity.cpp

@@ -31,6 +31,8 @@ void AIEntity::initAI() {
 
 void AIEntity::updateAI() {
     lua_State *L = g.get_lua_context();
+    luwra::StateWrapper state(L);
+
     if(AI_ready && ai_name != nullptr) {
         try{
             lua_getglobal(L, ai_name);
@@ -45,14 +47,12 @@ void AIEntity::updateAI() {
             t.set("points", points);
             t.set("intent", (int)intent);
             t.get<luwra::NativeFunction<void>>("update")(t);
-
             lua_getglobal(L, ai_name);
             luwra::Table t2 = luwra::read<luwra::Table>(L, -1);
             intent = (MoveIntent)t2.get<int>("intent");
             apply_movement();
 
         }catch(std::exception e) {
-            WalrusRPG::Logger::error("Error while executing %s: %s", ai_name, e.what());
             AI_ready = false;
         }
     }

+ 26 - 8
src/pacman/AIPlayer.cpp

@@ -16,7 +16,6 @@ using namespace WalrusRPG;
 
 AIPlayer::AIPlayer(int x, int y, GameState &g, const char* filename, const char* ai_name): AIEntity(x, y, g, ai_name, filename), dead(false)
 {
-    intent = LEFT;
 }
 
 AIPlayer::~AIPlayer()
@@ -35,12 +34,31 @@ void AIPlayer::update(unsigned dt)
     }
 }
 
-void AIPlayer::render(unsigned dt, Camera& cam)
+void AIPlayer::render(unsigned dt, Camera& cam, Pixel col)
 {
-    if(dead) return;
-	put_rectangle({x-cam.get_x(), y-cam.get_y(),16,16}, Yellow);
-	if(x < 0)
-	put_rectangle({x-cam.get_x()+224, y-cam.get_y(),16,16}, Yellow);
-	if(x > 232)
-	put_rectangle({x-cam.get_x()-224, y-cam.get_y(),16,16}, Yellow);
+    put_rectangle({x-cam.get_x(), y-cam.get_y(),16,16}, col);
+    if(x < 0)
+    put_rectangle({x-cam.get_x()+224, y-cam.get_y(),16,16}, col);
+    if(x > 232)
+    put_rectangle({x-cam.get_x()-224, y-cam.get_y(),16,16}, col);
+    switch(intent)
+    {
+        case UP:
+        put_rectangle({x-cam.get_x(), y-cam.get_y(),16,2}, Red);
+        break;
+        case DOWN:
+        put_rectangle({x-cam.get_x(), y-cam.get_y()+14,16,2}, Red);
+        break;
+        case LEFT:
+        put_rectangle({x-cam.get_x(), y-cam.get_y(),2,16}, Red);
+        break;
+        case RIGHT:
+        put_rectangle({x-cam.get_x()+14, y-cam.get_y(),2,16}, Red);
+        break;
+
+    }
+    if(!AI_ready) {
+        put_line(x-cam.get_x(),y-cam.get_y(),x-cam.get_x()+16,y-cam.get_y()+16, Red);
+    }
+
 }

+ 2 - 1
src/pacman/AIPlayer.h

@@ -14,7 +14,8 @@ namespace Pacman
 		bool dead;
 		AIPlayer(int x, int y, GameState &g, const char* filename, const char* ai_name);
 		~AIPlayer();
-		virtual void render(unsigned dt, WalrusRPG::Camera& cam) override;
+		virtual void render(unsigned dt, WalrusRPG::Camera& cam) override {};
+		virtual void render(unsigned dt, WalrusRPG::Camera& cam, WalrusRPG::Graphics::Pixel col);
 		virtual void update(unsigned dt) override;
 	};
 }

+ 2 - 2
src/pacman/GameState.cpp

@@ -240,8 +240,8 @@ void GameState::render(unsigned dt)
 	// render_player(j1);
 	// render_player(j2);
 
-	p1->render(dt, cam);
-	p2->render(dt, cam);
+	p1->render(dt, cam, Yellow);
+	p2->render(dt, cam, Green);
 	blinky->render(dt, cam, Red);
 	inky->render(dt, cam, Cyan);
 	pinky->render(dt, cam, Pixel(255, 153, 204));

+ 1 - 1
src/pacman/GameState.h

@@ -19,9 +19,9 @@ namespace Pacman
 		WalrusRPG::Map map;
 		Pacgum gums[31][28];
 		WalrusRPG::Camera cam;
-		lua_State *L;
 		int remaining_pills;
 	public:
+		lua_State *L;
 		AIPlayer *p1;
 		AIPlayer *p2;
 		Ghost *blinky;

+ 21 - 1
src/pacman/Ghost.cpp

@@ -19,7 +19,6 @@ using namespace WalrusRPG;
 Ghost::Ghost(int x, int y, GameState &g, const char* filename, const char* ghost_name): AIEntity(x, y, g, ghost_name, filename),
     weak(false), dead_timer(0)
 {
-    intent = UP;
 }
 
 Ghost::~Ghost()
@@ -70,4 +69,25 @@ void Ghost::render(unsigned dt, Camera& cam, Pixel col)
 	put_rectangle({x-cam.get_x()+224, y-cam.get_y(),16,16}, col);
 	if(x > 232)
 	put_rectangle({x-cam.get_x()-224, y-cam.get_y(),16,16}, col);
+    switch(intent)
+    {
+        case NONE:
+        break;
+        case UP:
+        put_rectangle({x-cam.get_x(), y-cam.get_y(),16,2}, White);
+        break;
+        case DOWN:
+        put_rectangle({x-cam.get_x(), y-cam.get_y()+14,16,2}, White);
+        break;
+        case LEFT:
+        put_rectangle({x-cam.get_x(), y-cam.get_y(),2,16}, White);
+        break;
+        case RIGHT:
+        put_rectangle({x-cam.get_x()+14, y-cam.get_y(),2,16}, White);
+        break;
+
+    }
+    if(!AI_ready) {
+        put_line(x-cam.get_x(),y-cam.get_y(),x-cam.get_x()+16,y-cam.get_y()+16, White);
+    }
 }

+ 20 - 4
src/pacman/Player.cpp

@@ -42,11 +42,27 @@ void Player::update(unsigned dt)
 	apply_movement();
 }
 
-void Player::render(unsigned dt, Camera& cam)
+void Player::render(unsigned dt, Camera& cam, Pixel col)
 {
-	put_rectangle({x-cam.get_x(), y-cam.get_y(),16,16}, Yellow);
+	put_rectangle({x-cam.get_x(), y-cam.get_y(),16,16}, col);
 	if(x < 0)
-	put_rectangle({x-cam.get_x()+224, y-cam.get_y(),16,16}, Yellow);
+	put_rectangle({x-cam.get_x()+224, y-cam.get_y(),16,16}, col);
 	if(x > 232)
-	put_rectangle({x-cam.get_x()-224, y-cam.get_y(),16,16}, Yellow);
+	put_rectangle({x-cam.get_x()-224, y-cam.get_y(),16,16}, col);
+	switch(intent)
+	{
+		case UP:
+		put_rectangle({x-cam.get_x(), y-cam.get_y(),16,2}, Red);
+		break;
+		case DOWN:
+		put_rectangle({x-cam.get_x(), y-cam.get_y()+14,16,2}, Red);
+		break;
+		case LEFT:
+		put_rectangle({x-cam.get_x(), y-cam.get_y(),2,16}, Red);
+		break;
+		case RIGHT:
+		put_rectangle({x-cam.get_x()+14, y-cam.get_y(),2,16}, Red);
+		break;
+
+	}
 }

+ 2 - 1
src/pacman/Player.h

@@ -11,7 +11,8 @@ namespace Pacman
 	public:
 		Player(int x, int y, GameState &g, WalrusRPG::Input::Key kup, WalrusRPG::Input::Key kdown, WalrusRPG::Input::Key kleft, WalrusRPG::Input::Key kright);
 		~Player();
-		virtual void render(unsigned dt, WalrusRPG::Camera& cam) override;
+		virtual void render(unsigned dt, WalrusRPG::Camera& cam) override {};
+		virtual void render(unsigned dt, WalrusRPG::Camera& cam, WalrusRPG::Graphics::Pixel col);
 		virtual void update(unsigned dt) override;
 	};
 }