diff options
17 files changed, 132 insertions, 31 deletions
| Binary files differ diff --git a/assets/backgrounds/.DS_Store b/assets/backgrounds/.DS_Store Binary files differnew file mode 100644 index 0000000..e272705 --- /dev/null +++ b/assets/backgrounds/.DS_Store diff --git a/assets/backgrounds/backgrounds-data.lua b/assets/backgrounds/backgrounds-data.lua new file mode 100644 index 0000000..087ddf9 --- /dev/null +++ b/assets/backgrounds/backgrounds-data.lua @@ -0,0 +1,10 @@ +return { + "assets/backgrounds/city-background-1.png", + "assets/backgrounds/city-background-2.png", + "assets/backgrounds/city-background-3.png", + "assets/backgrounds/city-background-4.png", + "assets/backgrounds/city-background-5.png", + "assets/backgrounds/city-background-6.png", + "assets/backgrounds/city-background-7.png", + "assets/backgrounds/city-background-8.png", +}
\ No newline at end of file diff --git a/assets/backgrounds/city-background-2.png b/assets/backgrounds/city-background-2.png Binary files differnew file mode 100644 index 0000000..de3f04f --- /dev/null +++ b/assets/backgrounds/city-background-2.png diff --git a/assets/backgrounds/city-background-3.png b/assets/backgrounds/city-background-3.png Binary files differnew file mode 100644 index 0000000..a1b625b --- /dev/null +++ b/assets/backgrounds/city-background-3.png diff --git a/assets/backgrounds/city-background-4.png b/assets/backgrounds/city-background-4.png Binary files differnew file mode 100644 index 0000000..147989b --- /dev/null +++ b/assets/backgrounds/city-background-4.png diff --git a/assets/backgrounds/city-background-5.png b/assets/backgrounds/city-background-5.png Binary files differnew file mode 100644 index 0000000..971e57a --- /dev/null +++ b/assets/backgrounds/city-background-5.png diff --git a/assets/backgrounds/city-background-6.png b/assets/backgrounds/city-background-6.png Binary files differnew file mode 100644 index 0000000..2947551 --- /dev/null +++ b/assets/backgrounds/city-background-6.png diff --git a/assets/backgrounds/city-background-7.png b/assets/backgrounds/city-background-7.png Binary files differnew file mode 100644 index 0000000..28ada47 --- /dev/null +++ b/assets/backgrounds/city-background-7.png diff --git a/assets/backgrounds/city-background-8.png b/assets/backgrounds/city-background-8.png Binary files differnew file mode 100644 index 0000000..6928a6b --- /dev/null +++ b/assets/backgrounds/city-background-8.png diff --git a/assets/characters/.DS_Store b/assets/characters/.DS_Store Binary files differindex 358c1b2..a4ae90d 100644 --- a/assets/characters/.DS_Store +++ b/assets/characters/.DS_Store diff --git a/assets/characters/Cobalt Phantom/.DS_Store b/assets/characters/Cobalt Phantom/.DS_Store Binary files differindex 9ec0b2a..9955791 100644 --- a/assets/characters/Cobalt Phantom/.DS_Store +++ b/assets/characters/Cobalt Phantom/.DS_Store diff --git a/assets/characters/Emerald Venom/.DS_Store b/assets/characters/Emerald Venom/.DS_Store Binary files differindex 5f50018..472db25 100644 --- a/assets/characters/Emerald Venom/.DS_Store +++ b/assets/characters/Emerald Venom/.DS_Store diff --git a/assets/characters/Golden Radiance/.DS_Store b/assets/characters/Golden Radiance/.DS_Store Binary files differindex e1664d3..7f88958 100644 --- a/assets/characters/Golden Radiance/.DS_Store +++ b/assets/characters/Golden Radiance/.DS_Store diff --git a/assets/characters/characters-data.lua b/assets/characters/characters-data.lua index d3cef43..a90849e 100644 --- a/assets/characters/characters-data.lua +++ b/assets/characters/characters-data.lua @@ -1,7 +1,7 @@ return { { name = "Cobalt Phantom", - health = 100, + lives = 3, speed = 5, moves = {"teleportation", "quick_dashes", "smoke_screens", "strikes_from_the_shadows"}, asset_dir = "assets/characters/Cobalt Phantom", @@ -9,7 +9,7 @@ return { }, { name = "Emerald Venom", - health = 120, + lives = 4, speed = 4, moves = {"snake_whip", "venom_bite", "poison_of_the_past"}, asset_dir = "assets/characters/Emerald Venom", @@ -17,7 +17,7 @@ return { }, { name = "Golden Radiance", - health = 85, + lives = 5, speed = 8, moves = {"solar_boom", "flashbang", "flare_frenzy"}, asset_dir = "assets/characters/Golden Radiance", @@ -25,7 +25,7 @@ return { }, { name = "Crimson Reaper", - health = 180, + lives = 2, speed = 2, moves = {"soul_slash", "deaths_reach", "phantom_step", "grim_harvest"}, asset_dir = "assets/characters/Crimson Reaper", diff --git a/assets/scripts/local2P.lua b/assets/scripts/local2P.lua index c8e0aa5..7fd2efa 100644 --- a/assets/scripts/local2P.lua +++ b/assets/scripts/local2P.lua @@ -1,42 +1,80 @@ ---@diagnostic disable: undefined-global +backgrounds = require("assets.backgrounds.backgrounds-data") + +groundTiles = { + { x = 250, y = HEIGHT - 300, width = 200, height = 30 }, + { x = WIDTH - 250 - 200, y = HEIGHT - 300, width = 200, height = 30 }, +} + function SafeInitCharacter(character, default_x, default_y) character.x = character.x or default_x character.y = character.y or default_y character.y_velocity = character.y_velocity or 1 character.current_sprite = character.asset_dir .. "/sprites/idle.png" + character.can_jump = false + character.knockback_counter = 0 + character.combo_chain = 0 + character.can_apply_knockback = false end function Setup() - SafeInitCharacter(player1Character, 250, 250) - SafeInitCharacter(player2Character, WIDTH - 250 - (250 / 2), 250) + local bgIndex = math.random(1, #backgrounds) + setBgImage(backgrounds[bgIndex]) + SafeInitCharacter(player1Character, 250, 150) + SafeInitCharacter(player2Character, WIDTH - 250 - (250 / 2), 150) end gravity = 1.2 -- POSITIVE gravity -floor_y = HEIGHT - 250 + +function DrawGroundTiles() + for _, tile in ipairs(groundTiles) do + queueRectForRender(tile.x, tile.y, tile.width, tile.height, 100, 100, 100, 255) -- gray boxes + end +end + +function IsOnGround(character) + for _, tile in ipairs(groundTiles) do + local characterFeetY = character.y + 128 + + local isWithinX = character.x + 64 > tile.x and character.x < tile.x + tile.width + local isTouchingY = characterFeetY >= tile.y and characterFeetY <= tile.y + tile.height + + if isWithinX and isTouchingY then + character.y = tile.y - 128 + return true + end + end + return false +end function HandleP1Input() - if Input.isKeyPressedOnce("W") and player1Character.y == floor_y then - player1Character.y_velocity = player1Character.jump_strength * -1.0; + if Input.isKeyPressedOnce("W") and player1Character.can_jump then + player1Character.y_velocity = player1Character.jump_strength * -1.0 + player1Character.can_jump = false end if Input.isKeyDown("D") then - player1Character.x = player1Character.x + player1Character.speed; + player1Character.x = player1Character.x + player1Character.speed end if Input.isKeyDown("A") then - player1Character.x = player1Character.x - player1Character.speed; + player1Character.x = player1Character.x - player1Character.speed + end + if Input.isKeyPressedOnce("F") then + end end function HandleP2Input() - if Input.isKeyPressedOnce("UP") and player2Character.y == floor_y then - player2Character.y_velocity = player2Character.jump_strength * -1.0; + if Input.isKeyPressedOnce("UP") and player2Character.can_jump then + player2Character.y_velocity = player2Character.jump_strength * -1.0 + player2Character.can_jump = false end if Input.isKeyDown("RIGHT") then - player2Character.x = player2Character.x + player2Character.speed; + player2Character.x = player2Character.x + player2Character.speed end if Input.isKeyDown("LEFT") then - player2Character.x = player2Character.x - player2Character.speed; + player2Character.x = player2Character.x - player2Character.speed end end @@ -45,18 +83,18 @@ function Update() player1Character.y_velocity = player1Character.y_velocity + gravity player1Character.y = player1Character.y + player1Character.y_velocity - if player1Character.y > floor_y then - player1Character.y = floor_y + if IsOnGround(player1Character) then player1Character.y_velocity = 0 + player1Character.can_jump = true end -- P2 physics player2Character.y_velocity = player2Character.y_velocity + gravity player2Character.y = player2Character.y + player2Character.y_velocity - if player2Character.y > floor_y then - player2Character.y = floor_y + if IsOnGround(player2Character) then player2Character.y_velocity = 0 + player2Character.can_jump = true end -- Render @@ -72,6 +110,42 @@ function Update() math.floor(player2Character.y) ) + local fontFile = "assets/fonts/OpenSans-Bold.ttf" + local fontSize = 24 + local text = player1Character.name + + local x = 20 + local y = 20 + + queueTextForRender(text, fontFile, x, y, fontSize, 0, 0, 0, 255) + + local text = player2Character.name + + local textWidth = getTextWidth(fontFile, fontSize, text) + local x = WIDTH - textWidth - 20 + local y = 20 + + queueTextForRender(text, fontFile, x, y, fontSize, 0, 0, 0, 255) + + local fontFile = "assets/fonts/OpenSans-MediumItalic.ttf" + local fontSize = 34 + local text = tonumber(player1Character.knockback_counter) + + local x = 40 + local y = 40 + + queueTextForRender(text, fontFile, x, y, fontSize, 0, 0, 0, 255) + + local fontFile = "assets/fonts/OpenSans-MediumItalic.ttf" + local fontSize = 34 + local text = tostring(player2Character.knockback_counter) + + local textWidth = getTextWidth(fontFile, fontSize, text) + local x = WIDTH - textWidth - 40 + + queueTextForRender(text, fontFile, x, y, fontSize, 0, 0, 0, 255) + + DrawGroundTiles() -- Input HandleP1Input() diff --git a/src/main.cpp b/src/main.cpp index c170abe..b2a48d9 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -54,7 +54,6 @@ SDL_Color veryDarkGrey = {30, 30, 47, 255}; const char *globalFontFile = "assets/fonts/OpenSans-Regular.ttf"; // Forward declarations -int l_move_player(lua_State *L); int l_keycode_from_string(lua_State *L); int l_set_background_image(lua_State *L); int l_queue_texture_for_render(lua_State *L); @@ -88,6 +87,11 @@ struct QueuedText SDL_Color color = {255, 255, 255, 255}; }; +struct QueuedRect { + SDL_Rect rect; + SDL_Color color; +}; + std::vector<QueuedTexture> textureList = {}; std::map<std::string, SDL_Texture *> textureCache; @@ -96,17 +100,9 @@ std::vector<QueuedButton> buttonList = {}; std::vector<QueuedText> textList = {}; std::map<std::pair<std::string, int>, TTF_Font *> textCache; -SDL_Rect rect = {WIDTH / 2, HEIGHT / 2, 50, 50}; -SDL_Texture *background_texture = nullptr; +std::vector<QueuedRect> rectList = {}; -int l_move_player(lua_State *L) -{ - int dx = luaL_checkinteger(L, 1); - int dy = luaL_checkinteger(L, 2); - rect.x += dx; - rect.y += dy; - return 0; -} +SDL_Texture *background_texture = nullptr; int l_keycode_from_string(lua_State *L) { @@ -137,6 +133,21 @@ int l_queue_button_for_render(lua_State *L) return 0; } +int l_queue_rect_for_render(lua_State* L) { + int x = luaL_checkinteger(L, 1); + int y = luaL_checkinteger(L, 2); + int w = luaL_checkinteger(L, 3); + int h = luaL_checkinteger(L, 4); + Uint8 r = luaL_checkinteger(L, 5); + Uint8 g = luaL_checkinteger(L, 6); + Uint8 b = luaL_checkinteger(L, 7); + Uint8 a = luaL_checkinteger(L, 8); + SDL_Rect rect = {x, y, w, h}; + SDL_Color color = {r, g, b, a}; + rectList.push_back({rect, color}); + return 0; +} + int l_queue_text_for_render(lua_State *L) { std::string text = (std::string)luaL_checkstring(L, 1); @@ -313,7 +324,6 @@ void call_lua_function(lua_State *L, const char *func_name) void expose_c_functions() { - lua_register(L, "movePlayer", l_move_player); lua_register(L, "getKeycodeByName", l_keycode_from_string); lua_register(L, "setBgImage", l_set_background_image); lua_register(L, "queueTextureForRender", l_queue_texture_for_render); @@ -322,6 +332,7 @@ void expose_c_functions() lua_register(L, "queueTextForRender", l_queue_text_for_render); lua_register(L, "getTextWidth", l_get_text_width); lua_register(L, "quitGame", l_quit_game); + lua_register(L, "queueRectForRender", l_queue_rect_for_render); } int main() @@ -479,6 +490,12 @@ int main() } buttonList.clear(); + for (const auto& rect: rectList) { + SDL_SetRenderDrawColor(renderer, rect.color.r, rect.color.g, rect.color.b, rect.color.a); + SDL_RenderFillRect(renderer, &rect.rect); + } + rectList.clear(); + for (const auto &text : textList) { std::pair<std::string, int> key = {text.font_file, text.font_size}; |
