commit b6f946f82290234be7f2a89e2129b5685f18f2dc Author: zuckerberg <5-zuckerberg@users.noreply.git.neet.dev> Date: Fri Aug 27 12:48:57 2021 -0400 initial commit diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..80d372a --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2021 zuckerberg + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/README.txt b/README.txt new file mode 100644 index 0000000..cc9e9d5 --- /dev/null +++ b/README.txt @@ -0,0 +1 @@ +A Cute little fish game made in one hour for a game jam. Depends on love2d diff --git a/background.png b/background.png new file mode 100644 index 0000000..4588866 Binary files /dev/null and b/background.png differ diff --git a/fish_swim.png b/fish_swim.png new file mode 100644 index 0000000..5e4e7e2 Binary files /dev/null and b/fish_swim.png differ diff --git a/food.png b/food.png new file mode 100644 index 0000000..73a3a12 Binary files /dev/null and b/food.png differ diff --git a/grass.png b/grass.png new file mode 100644 index 0000000..335b4f3 Binary files /dev/null and b/grass.png differ diff --git a/main.lua b/main.lua new file mode 100644 index 0000000..82eb90d --- /dev/null +++ b/main.lua @@ -0,0 +1,179 @@ +local i,v +local j,k + +local speed = 300 +local food = {} +local shark = {} +local player = { + x = 300, + y = 300, + r = 30, + flip = false +} +local img = {} + +local score = 0 +local lives = 3 + +function love.load() + math.randomseed(os.time()) + love.mouse.setVisible(false) + addFood() + addShark() + img.fish = love.graphics.newImage("fish_swim.png") + img.food = love.graphics.newImage("food.png") + img.grass = love.graphics.newImage("grass.png") + img.background = love.graphics.newImage("background.png") + img.shark = love.graphics.newImage("shark.png") +end + +function love.update(dt) + for i,v in ipairs(food) do + v.x = v.x + dt*v.dx + v.y = v.y + dt*v.dy + if v.x < -30 then + v.x = 830 + elseif v.y < -30 then + v.y = 630 + elseif v.x > 830 then + v.x = -30 + elseif v.y > 630 then + v.y = -30 + end + end + for i,v in ipairs(shark) do + v.x = v.x + dt*v.dx + v.y = v.y + dt*v.dy + if v.x < -50 then + v.x = 850 + elseif v.y < -50 then + v.y = 650 + elseif v.x > 850 then + v.x = -50 + elseif v.y > 650 then + v.y = -50 + end + end + + toRemove = {} + for j,k in ipairs(shark) do + if collide(player,k) then + table.insert(toRemove,j) + end + end + if #toRemove ~= 0 then + player.x = 300 + player.y = 300 + end + lives = lives - #toRemove + for i,v in ipairs(toRemove) do + table.remove(shark, v) + end + for i,v in ipairs(toRemove) do + addShark() + addShark() + end + + -- check to see if player ate food + toRemove = {} + for j,k in ipairs(food) do + if collide(player,k) then + table.insert(toRemove,j) + if lives > 0 then + score = score + 1 + addShark() + end + end + end + for i,v in ipairs(toRemove) do + table.remove(food, v) + end + for i,v in ipairs(toRemove) do + addFood() + end + + -- TODO: make this logic better + if math.floor(score) ~= math.floor(score + dt) then + if math.random(0,4) == 0 then + addFood() + end + if math.floor(score + dt) % 10 == 0 then + addShark() + end + if score % 2 == 0 then + addShark() + end + end + + if love.keyboard.isDown("escape") then + love.event.quit() + end + + if love.keyboard.isDown("left") then + player.x = player.x - dt * speed + player.flip = false + end + if love.keyboard.isDown("right") then + player.x = player.x + dt * speed + player.flip = true + end + if love.keyboard.isDown("up") then + player.y = player.y - dt * speed + end + if love.keyboard.isDown("down") then + player.y = player.y + dt * speed + end +end + +function love.draw() + + love.graphics.draw(img.background, 0, 0) + + for i,v in ipairs(food) do + -- love.graphics.circle("fill", v.x, v.y, v.r) + love.graphics.draw(img.food, v.x - 30, v.y - 30, 0, 0.3) + end + + for i,v in ipairs(shark) do + -- love.graphics.circle("fill", v.x, v.y, v.r) + love.graphics.draw(img.shark, v.x - 70, v.y - 60, 0, 0.25, 0.25) + end + + -- love.graphics.circle("fill", player.x, player.y, player.r) + local flip = 1 + local pos = 0 + if player.flip then + flip = -1 + pos = 100 + end + love.graphics.draw(img.fish, pos + player.x - 50, player.y - 30, 0, flip * 0.2, 0.2) + + love.graphics.print('Score: ' .. math.floor(score), 10, 0, 0, 3) + love.graphics.print('Lives: ' .. lives, 10, 35, 0, 3) + + + if lives <= 0 then + love.graphics.print('GAME OVER', 0, 0, 0, 10) + end +end + +function addFood() + table.insert(food, { + x = 830, y=math.random(100, 500), r=math.random(10,20), + dx=-math.random(30,50), dy=math.random(30,50) + }) +end + +function addShark() + table.insert(shark, { + x = 850, y=math.random(0, 600), r=math.random(40,50), + dx=3*math.random(-30,-50), dy=(math.random(0,2)-1)*math.random(-30,-50) + }) +end + +function collide(a, b) + local x = a.x - b.x + local y = a.y - b.y + local r = a.r + b.r + return x*x + y*y <= r*r +end \ No newline at end of file diff --git a/shark.png b/shark.png new file mode 100644 index 0000000..78ec388 Binary files /dev/null and b/shark.png differ