From 0477ba0bf5e86d8aa1fc425cee6a8baf8bc28db6 Mon Sep 17 00:00:00 2001 From: Darkwater Date: Sat, 16 Nov 2013 00:00:15 +0100 Subject: [PATCH] Released v0.1 Create arena.map if there's no map folder yet Player has fire spread Bullets travel slower --- README.md | 1 + bute.lua | 19 ++++++++++++------- main.lua | 5 +++++ ship.lua | 29 +++++++++++++++++++++++------ 4 files changed, 41 insertions(+), 13 deletions(-) diff --git a/README.md b/README.md index 3a0ce66..068d930 100644 --- a/README.md +++ b/README.md @@ -4,6 +4,7 @@ Lazors in Space It's a space shooter inspired by Pewpew and Geometry Wars. Requires [LÖVE](http://love2d.org/) [0.9.0](https://bitbucket.org/rude/love/) to play. Have a progress vlog: +- [`current`](http://dev.novaember.com/s/13-11-15_23-56-54_446338902.webm) - [`95b7b9a`](http://dev.novaember.com/s/13-10-23_22-01-27_140703724.webm) - [`21d7a0c`](http://dev.novaember.com/s/13-10-10_15-51-48_834298746.webm) - [`2a465d3`](http://dev.novaember.com/s/13-10-06_00-27-19_050951243.webm) diff --git a/bute.lua b/bute.lua index e567ed8..e93e592 100644 --- a/bute.lua +++ b/bute.lua @@ -9,13 +9,16 @@ Bute = class("Bute", BaseAI) -- function Bute:initialize(x, y) BaseAI.initialize(self, x, y) - self.speed = math.random(2, 5) + self.speed = math.random(5, 10) -- self.turnSspeed = 500 - self.body:setLinearDamping(3) + self.body:setLinearDamping(0.1) self.fixture:setRestitution(1) self.nextFire = 0 - self.fireInterval = 0.1 + self.fireInterval = {100, 500} + + self.nextMove = 0 + self.moveInterval = {10, 200} self.moveOffset = math.random(-20, 20) / 180 * math.pi @@ -38,15 +41,17 @@ function Bute:update(dt) self:aimInDirection(ang) - if math.random(1, 600) > 500 + dt * 100 then + if self.nextMove <= love.timer.getTime() then + self.nextMove = love.timer.getTime() + math.random(unpack(self.moveInterval)) / 100 + self:pushInDirection(utils.randomAngle(), self.speed) end - if self.nextFire <= love.timer.getTime() and math.random(1,200) == 1 then - self.nextFire = love.timer.getTime() + self.fireInterval + if self.nextFire <= love.timer.getTime() then + self.nextFire = love.timer.getTime() + math.random(unpack(self.fireInterval)) / 100 - Bullet:new(self.body:getX(), self.body:getY(), self.body:getAngle(), 20, colgroup.ENEMY) + Bullet:new(self.body:getX(), self.body:getY(), self.body:getAngle(), 8, colgroup.ENEMY) end diff --git a/main.lua b/main.lua index b00d2bb..27bbd61 100644 --- a/main.lua +++ b/main.lua @@ -1,6 +1,11 @@ function love.load() love.physics.setMeter(64) + if not love.filesystem.isDirectory("maps") then + love.filesystem.createDirectory("maps") + love.filesystem.write("maps/arena.map", [=[{"author":"Darkwater","name":"Arena","mapdata":[["StaticDebris",{"points":[-600,0,0,-600,600,0,0,600]}],["StaticDebris",{"points":[-400,-200,-400,200,-600,0]}],["StaticDebris",{"points":[-200,-400,0,-600,200,-400]}],["StaticDebris",{"points":[400,-200,400,200,600,0]}],["StaticDebris",{"points":[-200,400,200,400,0,600]}],["EntitySpawner",{"y":0,"x":-350,"amount":[1,4],"interval":[1,12],"data":[],"type":"Bute"}],["EntitySpawner",{"y":-350,"x":0,"amount":[1,4],"interval":[1,12],"data":[],"type":"Bute"}],["EntitySpawner",{"y":0,"x":350,"amount":[1,4],"interval":[1,12],"data":[],"type":"Bute"}],["EntitySpawner",{"y":350,"x":0,"amount":[1,4],"interval":[1,12],"data":[],"type":"Bute"}],["StaticDebris",{"points":[-400,-200,-200,-200,-200,-400]}],["StaticDebris",{"points":[200,400,400,200,200,200]}],["StaticDebris",{"points":[-400,200,-200,200,-200,400]}],["StaticDebris",{"points":[200,-400,400,-200,200,-200]}]]}]=]) + end + class = require("middleclass") require("json") require("constants") diff --git a/ship.lua b/ship.lua index fb5028d..d040d92 100644 --- a/ship.lua +++ b/ship.lua @@ -17,8 +17,9 @@ function Ship:initialize(x, y) self.fixture:setGroupIndex(colgroup.PLAYER) self.nextFire = 0 - self.fireInterval = 0.12 - self.accuracy = 10 -- TODO: change accuracy according to distance of mouse? + self.fireInterval = 0.08 + self.fireSpread = false -- to toggle between double/single shot + self.spread = 0.1 -- TODO: change spread according to distance of mouse? self.damage = 5 @@ -55,10 +56,13 @@ function Ship:update(dt) if love.mouse.isDown("l") and self.nextFire <= love.timer.getTime() then self.nextFire = love.timer.getTime() + self.fireInterval - local ang = self.body:getAngle()-- + math.random(-self.accuracy, self.accuracy) / 100 - local dx = math.cos(ang) * 15 - local dy = math.sin(ang) * 15 - Bullet:new(self.body:getX() + dx, self.body:getY() + dy, ang, 20, colgroup.PLAYER) + if self.fireSpread then + self:shoot(self.body:getAngle() + self.spread) + self:shoot(self.body:getAngle() - self.spread) + else + self:shoot(self.body:getAngle()) + end + self.fireSpread = not self.fireSpread sounds.play("player_shoot") end @@ -125,3 +129,16 @@ end function Ship:aimInDirection(ang) self.body:setAngle(ang) end + + +--- +-- Ship:shoot +-- Shoots a bullet +-- +-- @param ang The direction of the bullet (radians) +-- +function Ship:shoot(ang) + local dx = math.cos(ang) * 15 + local dy = math.sin(ang) * 15 + Bullet:new(self.body:getX() + dx, self.body:getY() + dy, ang, 12, colgroup.PLAYER) +end