Madiwka3 3 роки тому
джерело
коміт
abcb07a9e3
23 змінених файлів з 329 додано та 48 видалено
  1. BIN
      entities/enemy/cannon.png
  2. +46
    -0
      entities/enemy/enemy.lua
  3. BIN
      entities/enemy/enemy.png
  4. BIN
      entities/enemy/missile-01.png
  5. +42
    -0
      entities/enemy/projectile.lua
  6. BIN
      entities/enemy/rlaunch.wav
  7. BIN
      entities/planet/teleport.wav
  8. +2
    -1
      explosion.lua
  9. +0
    -4
      levels/level1.lua
  10. +1
    -5
      levels/level2.lua
  11. +0
    -6
      levels/level3.lua
  12. +0
    -6
      levels/level4.lua
  13. +0
    -6
      levels/level5.lua
  14. +107
    -0
      levels/level6.lua
  15. +17
    -3
      levels/levelgeneral.lua
  16. +2
    -2
      levels/menu.lua
  17. +22
    -4
      levels/practice.lua
  18. +8
    -0
      levels/selectlv.lua
  19. +7
    -0
      main.lua
  20. +17
    -4
      readme.md
  21. +52
    -5
      src/GUI.lua
  22. +2
    -0
      src/dependencies.lua
  23. +4
    -2
      src/musicController.lua

BIN
entities/enemy/cannon.png Переглянути файл

Перед Після
Ширина: 48  |  Висота: 48  |  Розмір: 1.4 KiB

+ 46
- 0
entities/enemy/enemy.lua Переглянути файл

@@ -0,0 +1,46 @@
enemy = Class{}

G = 6.67e-5

function enemy:init(x, y, del, tm)
self.x = x
self.y = y
self.image = love.graphics.newImage("entities/enemy/enemy.png")
self.cannon = love.graphics.newImage("entities/enemy/cannon.png")
self.w = self.image:getWidth()
self.h = self.image:getHeight()
self.cannonw = self.cannon:getWidth()
self.cannonh = self.cannon:getHeight()
self.angle = 0
self.deletable = del
self.maxtimer = tm
self.destX = x
self.timer = tm
self.color = {1,1,1,1}
self.appeared = false
end

function enemy:update(dt)
self.timer = self.timer - dt
if self.timer <= 0 then
self.timer = self.maxtimer
self:shoot()
end
local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2)
self.angle = math.atan( (firstShip.y - self.y)/ (firstShip.x - self.x))
if self.x < firstShip.x then
self.angle = self.angle - 3.14159
end
end

function enemy:draw()
love.graphics.setColor(unpack(self.color))
love.graphics.draw(self.image, self.x, self.y, 0, 1, 1, self.w/2, self.w/2)
love.graphics.draw(self.cannon, self.x, self.y, self.angle-1.57, 1, 1, self.cannonw/2, self.cannonh/2)
end

function enemy:shoot()
table.insert(projectiles, projectile(self.x, self.y, 0.5, self.angle+3.14, 5))
sounds["launch"]:stop()
sounds["launch"]:play()
end

BIN
entities/enemy/enemy.png Переглянути файл

Перед Після
Ширина: 48  |  Висота: 48  |  Розмір: 2.1 KiB

BIN
entities/enemy/missile-01.png Переглянути файл

Перед Після
Ширина: 32  |  Висота: 32  |  Розмір: 1.2 KiB

+ 42
- 0
entities/enemy/projectile.lua Переглянути файл

@@ -0,0 +1,42 @@
projectile = Class{}

G = 6.67e-5

function projectile:init(x, y, v, angle, timer)
self.x = x
self.y = y
self.dx = 0
self.dy = 0
self.image = love.graphics.newImage("entities/enemy/missile-01.png")
self.w = self.image:getWidth()
self.h = self.image:getHeight()
self.angle = angle
self.v = v
self.timer = timer
self.killed = false
self.dx = math.cos(self.angle) * self.v
self.dy = math.sin(self.angle) * self.v
self.vx = 0
self.vy = 0
end

function projectile:update(dt)
local distanceToShip = math.sqrt((firstShip.x - self.x)^2 + (firstShip.y - self.y)^2)
self.timer = self.timer - dt
if self.timer <= 0 then
self.killed = true
end
self.vx = self.vx + self.dx
self.vy = self.vy + self.dy
self.x = self.x + self.vx
self.y = self.y + self.vy
if distanceToShip < firstShip.width/3 then
shipIsHit = true
sounds["close"]:stop()
sounds["boom"]:play()
end
end

function projectile:draw()
love.graphics.draw(self.image, self.x, self.y, self.angle, 1, 1, self.w/2, self.w/2)
end

BIN
entities/enemy/rlaunch.wav Переглянути файл


BIN
entities/planet/teleport.wav Переглянути файл


+ 2
- 1
explosion.lua Переглянути файл

@@ -30,7 +30,8 @@ function explosion:render(toggle)
love.graphics.setColor(unpack(self.color))
if toggle == "special" then
love.graphics.setColor(1,1,1,0.7/(self.range/6))
print(self.range)
-- print(self.range)
end
love.graphics.circle("fill", self.x, self.y, self.range * self.v, 100)
love.graphics.setColor(1,1,1,1)
end

+ 0
- 4
levels/level1.lua Переглянути файл

@@ -55,15 +55,11 @@ function level1.hint()
end
function level1.reset()
firstShip:reset()
for k in pairs(planets) do
planets[k] = nil
end
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
table.insert(planets, planet(700, 200, 50, 0.3, asteroidImage))
shipsleft = 1
shipIsHit = false
firstShip.fuel = 25
planetsleft = 3
end
function level1.GUIControl()
if (love.keyboard.isDown('a') and VCAM.x > WINDOW_WIDTH/2) then


+ 1
- 5
levels/level2.lua Переглянути файл

@@ -35,15 +35,11 @@ function level2.load()
end
function level2.reset()
firstShip:reset()
for k in pairs(planets) do
planets[k] = nil
end
firstShip.fuel = 50
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
table.insert(planets, planet(700, 500, 50, 0.3, asteroidImage))
shipsleft = 1
shipIsHit = false
planetsleft = 3
end
function level2.hint()
GUIDraw("left")
@@ -57,7 +53,7 @@ function level2.hint()
love.graphics.setColor(1,1,1,1)
end
if (VCAM.x < WINDOW_WIDTH*2) then
if love.keyboard.isDown('a') then
if love.keyboard.isDown('d') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("[D]→",100,50)


+ 0
- 6
levels/level3.lua Переглянути файл

@@ -55,16 +55,10 @@ function level3.hint()
end
function level3.reset()
firstShip:reset()
for k in pairs(planets) do
if planets[k].deletable then
planets[k] = nil
end
end
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
shipsleft = 1
firstShip.fuel = 75
shipIsHit = false
planetsleft = 3
end
function level3.GUIControl()


+ 0
- 6
levels/level4.lua Переглянути файл

@@ -37,16 +37,10 @@ end

function level4.reset()
firstShip:reset()
for k in pairs(planets) do
if planets[k].deletable then
planets[k] = nil
end
end
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
shipsleft = 1
firstShip.fuel = 100
shipIsHit = false
planetsleft = 3
end
function level4.GUIControl()
if (love.keyboard.isDown('a') and VCAM.x > -WINDOW_WIDTH/2) then


+ 0
- 6
levels/level5.lua Переглянути файл

@@ -38,16 +38,10 @@ end

function level5.reset()
firstShip:reset()
for k in pairs(planets) do
if planets[k].deletable then
planets[k] = nil
end
end
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
shipsleft = 1
firstShip.fuel = 100
shipIsHit = false
planetsleft = 10
end
function level5.GUIControl()
if (love.keyboard.isDown('w') and VCAM.y > -WINDOW_WIDTH) then


+ 107
- 0
levels/level6.lua Переглянути файл

@@ -0,0 +1,107 @@
level6 = Class{}
local levelLoaded = false
local M = {}
function level6.load()
shipsleft = 1
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
planetsleft = 3
gameStatus = "setup"
playbutts = {}
thrusterMax = 0
firstShip.fuel = 0
guibutts = {}
VCAM.x, VCAM.y = WINDOW_WIDTH/2, WINDOW_HEIGHT/2
explosions = {}
shipIsHit = false
guimenu = mainMenu()
reachedGoal = false
lvlbase = base(1600, 400)
levelLoaded = true
attackTimer = 5
table.insert(playbutts, menu:addButton("Return to setup", function()
gameStatus = "setup"
levelgeneral.reset()
end ))
table.insert(guibutts, menu:addButton("Release brake!", function ()
if shipsleft == 0 then
selectedItem = "none"
gameStatus = "play"
end
end
))
table.insert(guibutts, menu:addButton("To menu", function ()
levelgeneral.goBack()
end))
table.insert(cannons, enemy(10000, 400, false, 3))
table.insert(planets, planet(1600, 250, 50, 0.3, asteroidImage, "nodelete"))
table.insert(planets, planet(1600, 550, 50, 0.3, asteroidImage, "nodelete"))
end
function level6.hint()
GUIDraw("left")
love.graphics.setFont(tinyfont)
if (VCAM.x > WINDOW_WIDTH/2) then
if love.keyboard.isDown('a') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("←[A]",10,50)
love.graphics.setColor(1,1,1,1)
end
if (VCAM.x < WINDOW_WIDTH*2) then
if love.keyboard.isDown('d') then
love.graphics.setColor(1,0,0,1)
end
love.graphics.print("[D]→",100,50)
love.graphics.setColor(1,1,1,1)
end
end
function level6.reset()
firstShip:reset()
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
shipsleft = 1
projectiles = {}
cannons[1].x = 100000
cannons[1].destX = 100000
firstShip.fuel = 0
shipIsHit = false
attackTimer = 5
cannons[1].appeared = false

end
function level6.bonusUpdate(dt)
if not reachedGoal then
if attackTimer >= 0 then
attackTimer = attackTimer - dt
else
cannons[1].destX = 1200
cannons[1]:update(dt)
if not cannons[1].appeared then
sounds["appear"]:stop()
sounds["appear"]:play()
if #explosions == 0 then
table.insert(explosions, explosion(1400, 400, 100, {1,40/255,40/255,1}))
explosions[1].type = 1
end
cannons[1].appeared = true
end
end
for i in ipairs(projectiles) do
projectiles[i]:update(dt)
end
cannons[1].x = cannons[1].x - (math.abs(cannons[1].destX-cannons[1].x)/5)
end
end
function level6.GUIControl()
if (love.keyboard.isDown('a') and VCAM.x > WINDOW_WIDTH/2) then
VCAM.x = VCAM.x - 10
end
if (love.keyboard.isDown('d')) then
VCAM.x = VCAM.x + 10
end
end
function level6.goBack()
levelgeneral.goBack()
end
return level6


+ 17
- 3
levels/levelgeneral.lua Переглянути файл

@@ -56,6 +56,9 @@ function levelgeneral.update(dt)
for i in ipairs(planets) do
planets[i]:update(dt)
end
if currentLevel > 5 then
level.bonusUpdate(dt)
end
else
camera:follow(VCAM.x, VCAM.y)
end
@@ -75,12 +78,22 @@ function levelgeneral.draw()
planets[i]:draw(dt)
end
--love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
if shipIsHit then
for i, explosion in ipairs(explosions) do
for i in ipairs(cannons) do
cannons[i]:draw(dt)
end
for i in ipairs(projectiles) do
projectiles[i]:draw(dt)
end

for i, explosion in ipairs(explosions) do
if shipIsHit then
explosion:render()
--print("exploding")
else
explosion:render("special")
end
--print("exploding")
end

if reachedGoal then
love.graphics.clear(0,0,0,1)
love.graphics.setColor(30/255, 30/255, 30/255, 1)
@@ -92,6 +105,7 @@ function levelgeneral.draw()
frame = frame + 20
end
firstShip:draw()

camera:detach()
camera:draw()


+ 2
- 2
levels/menu.lua Переглянути файл

@@ -8,9 +8,9 @@ function menu.update(dt)
planets = {}
table.insert(planets, planet(love.math.random(100, WINDOW_WIDTH-100), love.math.random(100, WINDOW_HEIGHT-100), 90000000, 0.3, love.graphics.newImage("entities/planet/planet.png")))
if (planets[1].y < WINDOW_HEIGHT/2) then
firstShip.y = love.math.random(WINDOW_HEIGHT/2, WINDOW_HEIGHT)
firstShip.y = planets[1].y + love.math.random(300, 500)
else
firstShip.y = love.math.random(0, WINDOW_HEIGHT/2)
firstShip.y = planets[1].y - love.math.random(300, 500)
end
end
for i in ipairs(planets) do


+ 22
- 4
levels/practice.lua Переглянути файл

@@ -6,6 +6,7 @@ function practice.update(dt)
if not levelLoaded then
shipsleft = 1
planetsleft = 10
cannonsleft = 10
gameStatus = "setup"
playbutts = {}
guibutts = {}
@@ -60,6 +61,19 @@ function practice.update(dt)
for i in ipairs(planets) do
planets[i]:update(dt)
end
for i in ipairs(cannons) do
cannons[i]:update(dt)
end
for i in ipairs(projectiles) do
projectiles[i]:update(dt)
end
for i in ipairs(projectiles) do
if projectiles[i].killed then
table.remove(projectiles, i)
--print("killing")
end
end

currentScore = currentScore + math.sqrt(firstShip.dx^2 + firstShip.dy^2)
else
camera:follow(VCAM.x, VCAM.y)
@@ -75,6 +89,12 @@ function practice.draw()
for i in ipairs(planets) do
planets[i]:draw(dt)
end
for i in ipairs(cannons) do
cannons[i]:draw(dt)
end
for i in ipairs(projectiles) do
projectiles[i]:draw(dt)
end
--love.graphics.rectangle("fill",VCAM.x,VCAM.y,30,30)
if shipIsHit then
for i, explosion in ipairs(explosions) do
@@ -109,12 +129,11 @@ function practice.goBack()
gameStatus = "setup"
levelLoaded = false
gameState = "menu"
cannons = {}
end
function practice.reset()
firstShip:reset()
for k in pairs(planets) do
planets[k] = nil
end
projectiles = {}
shipsleft = 1
if currentScore > saveData.score then
@@ -123,7 +142,6 @@ function practice.reset()
end
currentScore = 0
shipIsHit = false
planetsleft = 10
firstShip.fuel = 99999
end
function practice.GUIControl()


+ 8
- 0
levels/selectlv.lua Переглянути файл

@@ -38,6 +38,14 @@ table.insert(levels, menu:addButton("Level 2", function ()
currentLevel = 5
end
end ))
table.insert(levels, menu:addButton("Level 6", function ()
if saveData.levelsBeaten > 4 then
menuLoaded = false
objReset()
gameState = "levelgeneral"
currentLevel = 6
end
end ))


table.insert(levels, menu:addButton("Go Back", function ()


+ 7
- 0
main.lua Переглянути файл

@@ -21,9 +21,16 @@ saveData = {

planets = {}
buttons = {}
cannons = {}
projectiles = {}
menu = mainMenu()

function love.load()
print(love.filesystem.getAppdataDirectory())
print(love.filesystem.getSaveDirectory())
print(love.filesystem.areSymlinksEnabled())
print(love.filesystem.createDirectory('.'))
love.filesystem.newFile("File")
testwalls = love.filesystem.load("save")
if testwalls ~= nil then
saveData = love.filesystem.load("save")()


+ 17
- 4
readme.md Переглянути файл

@@ -1,11 +1,24 @@
#Nuclear Gravity (name subjecct for change)
# NuclearGravity
## _The long-awaited sequel to NuclearPong (totally not)_

Have you ever used gravity to escape to your base when your spaceship's fuel runs out? no? well you should




In this new game you do exactly that. WASD controls camera, everything else is done via the mouse button.
NuclearGravity is a game about... well, gravity!
You have to strategically place planets in space in order for your ship to use their gravitational fields to get itself to its base.
Some nice features include:

- Realistic gravity
- Practice to beat your score!
- More coming...


Installation is simple, just download the windows EXE release from the releases tab!
If you're on linux, then clone the repo, and use debug.sh to launch the game. Linux binary coming soon!
The prerequisites are **love** and **zip**
If you're on arch, install the prerequisites with:
``sudo pacman -S love zip
``


To launch the game, use debuggame.sh. Lua is required

+ 52
- 5
src/GUI.lua Переглянути файл

@@ -1,5 +1,6 @@
selectedItem = "none"
local planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
local cannonImage = love.graphics.newImage("entities/enemy/enemy.png")
function GUIDraw(mode)
--MAIN
love.graphics.setColor(1,1,1,1)
@@ -20,13 +21,17 @@ function GUIDraw(mode)
GUIButton(shipsleft, shipImage, menuX + 60, menuY+WINDOW_HEIGHT*0.2, function() selectedItem = "ship" end, 1, 1, {1,1,1,1}, 1.57)
--SHIP
--PLANET
GUIButton(planetsleft, planetImage, menuX + 60, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "planet" end, 0.5, 0.5, {1,1,1,1}, 1.57)
for i, explosion in ipairs(explosions) do
explosion:render("special")
--print("exploding")
end
if gameState == "practice" then
GUIButton(cannonsleft, cannonImage, menuX + 240, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "cannon" end, 1, 1, {1,1,1,1}, 0)
end

--PLANET

--CANNON
GUIButton(planetsleft, planetImage, menuX + 60, menuY+WINDOW_HEIGHT*0.4, function() selectedItem = "planet" end, 0.5, 0.5, {1,1,1,1}, 1.57)
--CANNON


--PLACING
local mx, my = love.mouse.getPosition()
@@ -182,6 +187,8 @@ function GUIDraw(mode)
if love.keyboard.mouseisReleased then
love.keyboard.mouseisReleased = false
table.insert(planets, planet(vmx, vmy, 100000000, 0.3, planetImage))
sounds["planet"]:stop()
sounds["planet"]:play()
planetImage = love.graphics.newImage("entities/planet/planet" .. math.random(1, 18) .. ".png")
planetsleft = planetsleft-1
end
@@ -189,6 +196,21 @@ function GUIDraw(mode)
selectedItem = "none"
end
end
if selectedItem == "cannon" and mx < menuX then
local shipW = cannonImage:getWidth()
local shipH = cannonImage:getHeight()
love.graphics.draw(cannonImage,mx,my,0, 1, 1, shipW/2, shipH/2)
if love.keyboard.mouseisReleased then
love.keyboard.mouseisReleased = false
table.insert(cannons, enemy(vmx, vmy, true, love.math.random(1,3)))
sounds["planet"]:stop()
sounds["planet"]:play()
cannonsleft = cannonsleft - 1
end
if cannonsleft == 0 then
selectedItem = "none"
end
end
if selectedItem == "eraser" then
local hot = (vmx > firstShip.x-firstShip.height/2 and vmx < firstShip.x+firstShip.height and vmy > firstShip.y-firstShip.width/2 and vmy < firstShip.y - firstShip.width/2 + firstShip.width)
if hot then
@@ -232,6 +254,28 @@ function GUIDraw(mode)
end
end
end
for j in ipairs(cannons) do
if cannons[j].deletable then
local hot = (vmx > cannons[j].x-cannons[j].w*0.3/2 and vmx < cannons[j].x+cannons[j].w*0.3 and vmy > cannons[j].y-cannons[j].w*0.3/2 and vmy < cannons[j].y + cannons[j].w*0.3)
if hot then
cannons[j].color = {1,0,0,1}
--print("hot")
else
cannons[j].color = {1,1,1,1}
--print(mx .. " " .. my .. " " .. firstShip.x .. " " .. firstShip.y .. " " .. firstShip.width .. firstShip.height)
end
local pressed = love.keyboard.mouseisReleased
if location == "android" then
pressed = love.mouse.isDown(1)
end
if pressed and hot then
love.keyboard.mouseisReleased = false
table.remove(cannons, j)
cannonsleft = cannonsleft + 1
break
end
end
end
end
--PLACING

@@ -239,6 +283,9 @@ function GUIDraw(mode)
--REMOVE TOOL
trashbin = love.graphics.newImage("entities/trashbin.png")
GUIButton("inf", trashbin, menuX + 60, menuY+WINDOW_HEIGHT*0.6, function() selectedItem = "eraser" end, 1, 1, {1,1,1,1}, 0)
GUIButton("clr", trashbin, menuX + 240, menuY+WINDOW_HEIGHT*0.6, function() for i in ipairs(planets) do if planets[i].deletable then planetsleft = planetsleft + 1 planets[i] = nil end end for i in ipairs(cannons) do if cannons[i].deletable then cannonsleft = cannonsleft + 1 cannons[i] = nil end end firstShip.x = -9000
firstShip.destX = -9000
shipsleft = 1 end, 1, 1, {0,0,1,1}, 0)
--REMOVE TOOL

--START BUTTON


+ 2
- 0
src/dependencies.lua Переглянути файл

@@ -12,6 +12,8 @@ require 'stateMachine'
require 'entities/base/base'
require 'entities/camera/VCAM'
require 'src/musicController'
require 'entities/enemy/enemy'
require 'entities/enemy/projectile'
tick = require 'src/tick'
utf8 = require("utf8")
serialize = require 'src/ser'

+ 4
- 2
src/musicController.lua Переглянути файл

@@ -2,11 +2,13 @@ sounds = {
["boom"] = love.audio.newSource("entities/planet/boom.wav", "static"),
["close"] = love.audio.newSource("entities/planet/close.wav", "static"),
["appear"] = love.audio.newSource("entities/ship/Appear.wav", "static"),
["finish"] = love.audio.newSource("entities/ship/Finish.wav", "static")
["finish"] = love.audio.newSource("entities/ship/Finish.wav", "static"),
["planet"] = love.audio.newSource("entities/planet/teleport.wav", "static"),
["launch"] = love.audio.newSource("entities/enemy/rlaunch.wav", "static")
}
music = {
["menu"] = love.audio.newSource("entities/music/menu.ogg", "static"),
["play"] = love.audio.newSource("entities/music/play.wav", "static")
["play"] = love.audio.newSource("entities/music/play.mp3", "static")
}
mute = false
function musicController(orders, toggling)


Завантаження…
Відмінити
Зберегти