Add half asteroids

This commit is contained in:
Andros Fenollosa
2016-11-14 00:35:14 +01:00
parent 5147e66de4
commit 621c83c11e
394 changed files with 86 additions and 182385 deletions

View File

@ -0,0 +1,51 @@
local tools = require 'assets/scripts/tools'
local asteroids = {}
function asteroids.load(game)
local imgs = {
love.graphics.newImage('assets/sprites/asteroids/1.png'),
love.graphics.newImage('assets/sprites/asteroids/2.png'),
love.graphics.newImage('assets/sprites/asteroids/3.png')
}
local num = game.levelaa * 5
local max_speed = 5
-- Generate asteroids
asteroids.bodys = {}
for i=1, num do
local temp_img = imgs[math.random(1, tools.table_length(imgs))]
asteroids.bodys[i] = {
x = math.random(0, game.canvas.width - temp_img:getWidth()),
y = math.random(game.window.height / 2, game.canvas.height - temp_img:getHeight()),
speed = math.random(1, max_speed),
img = temp_img,
angle = math.random(0, 90)
}
end
end
function asteroids.update(dt, game)
-- Rotate asteroids
for key, asteroid in pairs(asteroids.bodys) do
value.angle = asteroid.angle + (dt * math.pi / 10)
value.x = asteroid.x - asteroid.speed
end
-- Destroy asteroids
for key, asteroid in pairs(asteroids.bodys) do
if value.x + asteroid.img:getWidth() < 0 then
table.remove(asteroid, key)
end
end
-- Create asteroids
if tools.table_length(asteroids.bodys) < asteroids.num then
local temp_img = imgs[math.random(1, table_length(imgs))]
asteroids.bodys[table_length(asteroids.bodys) + 1] = {
x = game.canvas.width + temp_img:getWidth(),
y = math.random(game.window.height, game.canvas.height - temp_img:getHeight()),
speed = math.random(1, max_speed),
img = temp_img,
angle = math.random(0, 90)}
end
end
return asteroids

View File

@ -4,11 +4,11 @@ local tools = require 'assets/scripts/tools'
local background = {}
local stars = {}
function background.load()
function background.load(game)
num_stars = 100
local star = {}
star.num_frames = 9
star.ani_speed = 1
star.num_frames = 8
star.ani_speed = .1
star.width_frame = 16
star.height_frame = 16
star.img = love.graphics.newImage('assets/sprites/background/star.png')
@ -16,10 +16,10 @@ function background.load()
star.animation = anim8.newAnimation(g('1-' .. star.num_frames, 1), star.ani_speed)
for i = 1, num_stars do
local temp_star = tools.clone_table(star)
temp_star.animation = anim8.newAnimation(g('1-' .. star.num_frames, 1), math.random(star.ani_speed, star.ani_speed * 2))
temp_star.animation = anim8.newAnimation(g('1-' .. star.num_frames, 1), math.random(star.ani_speed, star.ani_speed / 2))
temp_star.animation:gotoFrame(math.random(1, star.num_frames))
temp_star.x = math.random(-star.width_frame , canvas.width)
temp_star.y = math.random(-star.height_frame, canvas.height)
temp_star.x = math.random(-star.width_frame , game.canvas.width)
temp_star.y = math.random(-star.height_frame, game.canvas.height)
stars[i] = temp_star
end
end

18
assets/scripts/game.lua Normal file
View File

@ -0,0 +1,18 @@
local game = {}
function game.load()
-- Configuration
math.randomseed(os.time())
local width, height = love.window.getDesktopDimensions( display )
game.window = { width = width , height = height }
game.canvas = { width = width, height = 2880 }
love.window.setMode(game.window.width, game.window.height)
game.level = 1
-- Physics
local world_meter = 64
local gravity = 2
love.physics.setMeter(world_meter) -- Height earth in meters
game.world = love.physics.newWorld(0, gravity * world_meter, true) -- Make earth
end
return game

View File

@ -2,13 +2,11 @@ local anim8 = require 'assets/scripts/vendor/anim8'
local spaceship = {}
function spaceship.load(world)
local canvas = {}
canvas.width = 500
function spaceship.load(game)
-- power origin 1000
spaceship = { x = canvas.width / 2, y = 0 , power = 400 , size_collition = 28, polygons_collition = 8 }
spaceship = { x = game.canvas.width / 2, y = 0 , power = 400 , size_collition = 28, polygons_collition = 8 }
spaceship.img = love.graphics.newImage('assets/sprites/spaceship/body.png')
spaceship.body = love.physics.newBody(world, (canvas.width / 2) - (spaceship.img:getWidth() / 2) , spaceship.y, 'dynamic')
spaceship.body = love.physics.newBody(game.world, (game.canvas.width / 2) - (spaceship.img:getWidth() / 2) , spaceship.y, 'dynamic')
spaceship.shape = love.physics.newCircleShape(20)
spaceship.fixture = love.physics.newFixture(spaceship.body, spaceship.shape, 1)
spaceship.fixture:setRestitution(0.9)