Add camera

This commit is contained in:
Andros Fenollosa 2016-11-27 12:31:56 +01:00
parent fc553ac58f
commit 8b012de054
29 changed files with 104 additions and 49 deletions

Binary file not shown.

Binary file not shown.

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="love.to.android1126182750"
<manifest package="love.to.android1127120145"
android:versionCode="15"
android:versionName="0.9.2"
android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android">
@ -12,13 +12,13 @@
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="Game 1126182750"
android:label="Game 1127120145"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<service android:name=".DownloadService" />
<activity
android:name="LtaActivity"
android:configChanges="orientation|screenSize"
android:label="Game 1126182750"
android:label="Game 1127120145"
android:launchMode="singleTop"
android:screenOrientation="landscape" >
<intent-filter>

View File

@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<manifest package="love.to.android1126182750"
<manifest package="love.to.android1127120145"
android:versionCode="15"
android:versionName="0.9.2"
android:installLocation="auto" xmlns:android="http://schemas.android.com/apk/res/android">
@ -12,13 +12,13 @@
<application
android:allowBackup="true"
android:icon="@drawable/ic_launcher"
android:label="Game 1126182750"
android:label="Game 1127120145"
android:theme="@android:style/Theme.NoTitleBar.Fullscreen" >
<service android:name=".DownloadService" />
<activity
android:name="LtaActivity"
android:configChanges="orientation|screenSize"
android:label="Game 1126182750"
android:label="Game 1127120145"
android:launchMode="singleTop"
android:screenOrientation="landscape" >
<intent-filter>

View File

@ -1,5 +1,5 @@
#Last build type
#Sat, 26 Nov 2016 18:27:55 +0100
#Sun, 27 Nov 2016 12:01:51 +0100
build.last.target=debug

View File

@ -1,9 +1,9 @@
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes.dex : \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182750/BuildConfig.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182750/LtaActivity.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182750/R$attr.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182750/R$drawable.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182750/R.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1127120145/BuildConfig.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1127120145/LtaActivity.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1127120145/R$attr.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1127120145/R$drawable.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1127120145/R.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/DummyEdit.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$1.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$2.class \

View File

@ -1,9 +1,9 @@
# view AndroidManifest.xml #generated:45
-keep class love.to.android1126182750.DownloadActivity { <init>(...); }
-keep class love.to.android1127120145.DownloadActivity { <init>(...); }
# view AndroidManifest.xml #generated:17
-keep class love.to.android1126182750.DownloadService { <init>(...); }
-keep class love.to.android1127120145.DownloadService { <init>(...); }
# view AndroidManifest.xml #generated:18
-keep class love.to.android1126182750.LtaActivity { <init>(...); }
-keep class love.to.android1127120145.LtaActivity { <init>(...); }

View File

@ -1,3 +1,3 @@
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/gen/love/to/android1126182750/R.java \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/gen/love/to/android1127120145/R.java \
: /Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/res/drawable-xxhdpi/ic_launcher.png \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/AndroidManifest.xml \

View File

@ -1,5 +1,5 @@
/** Automatically generated file. DO NOT MODIFY */
package love.to.android1126182750;
package love.to.android1127120145;
public final class BuildConfig {
public final static boolean DEBUG = true;

View File

@ -5,7 +5,7 @@
* should not be modified by hand.
*/
package love.to.android1126182750;
package love.to.android1127120145;
public final class R {
public static final class attr {

View File

@ -1,4 +1,4 @@
package love.to.android1126182750;
package love.to.android1127120145;
import org.love2d.android.GameActivity;
public class LtaActivity extends GameActivity {}

View File

@ -1,2 +1,15 @@
local cam = gamera.new(0,0,2000,2000)
cam:setWorld(0,0,2000,2000)
local gamera = require 'assets/scripts/vendor/gamera'
camera = {}
local limit = 200
function camera.load(game)
camera.gcam = gamera.new(0, 0, game.window.width, game.window.height)
camera.gcam:setWorld(0, 0, game.canvas.width, game.canvas.height)
end
function camera.update(game, spaceship)
camera.gcam:setPosition(0, spaceship.y + limit)
end
return camera

View File

@ -1,52 +1,54 @@
local anim8 = require 'assets/scripts/vendor/anim8'
local spaceship = {}
spaceship.y = 0
local press_button = false
function spaceship.load(game)
-- power origin 1000
spaceship = { x = game.canvas.width / 2, y = 0 , power = 400 , size_collition = 28, polygons_collition = 8 }
spaceship.width = 156
spaceship.height = 143
spaceship.img = love.graphics.newImage('assets/sprites/spaceship/body.png')
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)
local g = anim8.newGrid(spaceship.width, spaceship.height, spaceship.img:getWidth(), spaceship.img:getHeight())
spaceship.animation_stop = anim8.newAnimation(g('1-1', 1), 0.1)
spaceship.animation_fire = anim8.newAnimation(g('2-5', 1), 0.01)
body = { x = game.canvas.width / 2, y = 0 , power = 400 , size_collition = 28, polygons_collition = 8 }
body.width = 156
body.height = 143
body.img = love.graphics.newImage('assets/sprites/spaceship/body.png')
body.body = love.physics.newBody(game.world, (game.canvas.width / 2) - (body.img:getWidth() / 2) , body.y, 'dynamic')
body.shape = love.physics.newCircleShape(20)
body.fixture = love.physics.newFixture(body.body, body.shape, 1)
body.fixture:setRestitution(0.9)
local g = anim8.newGrid(body.width, body.height, body.img:getWidth(), body.img:getHeight())
body.animation_stop = anim8.newAnimation(g('1-1', 1), 0.1)
body.animation_fire = anim8.newAnimation(g('2-5', 1), 0.01)
-- Light
light = {
img = love.graphics.newImage('assets/sprites/spaceship/light.png'),
y = spaceship.y
y = body.y
}
light.x = spaceship.x + (spaceship.img:getWidth() / 2) + (light.img:getWidth() / 2)
light.num_frames = 9
light.width = 16
light.height = 16
light.x = body.x + (body.img:getWidth() / 2) + (light.img:getWidth() / 2)
light.num_frames = 11
light.width = 74
light.height = 66
g = anim8.newGrid(light.width, light.height, light.img:getWidth(), light.img:getHeight())
light.animation = anim8.newAnimation(g('1-' .. light.num_frames, 1), 0.1)
light.animation = anim8.newAnimation(g('1-' .. light.num_frames, 1), 0.05)
end
function spaceship.update(dt)
-- Spaceship
spaceship.animation_fire:update(dt)
body.animation_fire:update(dt)
press_button = false
spaceship.y = body.body:getY()
-- Light
light.animation:update(dt)
light.x = spaceship.body:getX() + (spaceship.width / 2) + (light.width / 2)
light.y = spaceship.body:getY()
light.x = body.body:getX() + 43
light.y = body.body:getY() - 15
-- Controls
if control_up then
spaceship.body:applyForce(0, -spaceship.power)
body.body:applyForce(0, -body.power)
press_button = true
end
if control_right then
spaceship.body:applyForce(spaceship.power, 0)
body.body:applyForce(body.power, 0)
press_button = true
elseif control_left then
spaceship.body:applyForce(-spaceship.power, 0)
body.body:applyForce(-body.power, 0)
press_button = true
end
if control_quit then
@ -57,9 +59,9 @@ end
function spaceship.draw()
light.animation:draw(light.img, light.x, light.y)
if press_button then
spaceship.animation_fire:draw(spaceship.img, spaceship.body:getX(), spaceship.body:getY())
body.animation_fire:draw(body.img, body.body:getX(), body.body:getY())
else
spaceship.animation_stop:draw(spaceship.img, spaceship.body:getX(), spaceship.body:getY())
body.animation_stop:draw(body.img, body.body:getX(), body.body:getY())
end
end

View File

@ -36,4 +36,39 @@ function tools.clone_table(orig)
return copy
end
-- Print table
function tools.print_r(t)
local print_r_cache={}
local function sub_print_r(t,indent)
if (print_r_cache[tostring(t)]) then
print(indent.."*"..tostring(t))
else
print_r_cache[tostring(t)]=true
if (type(t)=="table") then
for pos,val in pairs(t) do
if (type(val)=="table") then
print(indent.."["..pos.."] => "..tostring(t).." {")
sub_print_r(val,indent..string.rep(" ",string.len(pos)+8))
print(indent..string.rep(" ",string.len(pos)+6).."}")
elseif (type(val)=="string") then
print(indent.."["..pos..'] => "'..val..'"')
else
print(indent.."["..pos.."] => "..tostring(val))
end
end
else
print(indent..tostring(t))
end
end
end
if (type(t)=="table") then
print(tostring(t).." {")
sub_print_r(t," ")
print("}")
else
sub_print_r(t," ")
end
print()
end
return tools

Binary file not shown.

After

Width:  |  Height:  |  Size: 58 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 58 KiB

After

Width:  |  Height:  |  Size: 56 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 1.6 KiB

After

Width:  |  Height:  |  Size: 32 KiB

View File

@ -3,10 +3,12 @@ local background = require 'assets/scripts/background'
local spaceship = require 'assets/scripts/spaceship'
local asteroids = require 'assets/scripts/asteroids'
local controls = require 'assets/scripts/controls'
local camera = require 'assets/scripts/camera'
-- LOAD
function love.load()
game.load()
camera.load(game)
background.load(game)
asteroids.load(game)
spaceship.load(game)
@ -18,14 +20,17 @@ function love.update(dt)
background.update(dt)
asteroids.update(dt, game)
spaceship.update(dt)
camera.update(game, spaceship)
controls.update(dt)
end
-- DRAW
function love.draw()
camera.gcam:draw(function(l,t,w,h)
background.draw()
spaceship.draw()
asteroids.draw()
end)
end
-- CONTROLS