Fix asteroids

This commit is contained in:
Andros Fenollosa 2016-11-26 18:26:48 +01:00
parent 621c83c11e
commit b86c084b28
31 changed files with 55 additions and 45 deletions

Binary file not shown.

Binary file not shown.

View File

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

View File

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

View File

@ -1,5 +1,5 @@
#Last build type #Last build type
#Sat, 12 Nov 2016 20:33:20 +0100 #Sat, 26 Nov 2016 18:22:56 +0100
build.last.target=debug 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.dex : \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112203313/BuildConfig.class \ /Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182250/BuildConfig.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112203313/LtaActivity.class \ /Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182250/LtaActivity.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112203313/R$attr.class \ /Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182250/R$attr.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112203313/R$drawable.class \ /Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182250/R$drawable.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112203313/R.class \ /Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1126182250/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/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$1.class \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$2.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 # view AndroidManifest.xml #generated:45
-keep class love.to.android1112203313.DownloadActivity { <init>(...); } -keep class love.to.android1126182250.DownloadActivity { <init>(...); }
# view AndroidManifest.xml #generated:17 # view AndroidManifest.xml #generated:17
-keep class love.to.android1112203313.DownloadService { <init>(...); } -keep class love.to.android1126182250.DownloadService { <init>(...); }
# view AndroidManifest.xml #generated:18 # view AndroidManifest.xml #generated:18
-keep class love.to.android1112203313.LtaActivity { <init>(...); } -keep class love.to.android1126182250.LtaActivity { <init>(...); }

View File

@ -1,3 +1,3 @@
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/gen/love/to/android1112203313/R.java \ /Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/gen/love/to/android1126182250/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/res/drawable-xxhdpi/ic_launcher.png \
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/AndroidManifest.xml \ /Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/AndroidManifest.xml \

View File

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

View File

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

View File

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

View File

@ -1,50 +1,59 @@
local tools = require 'assets/scripts/tools' local tools = require 'assets/scripts/tools'
local asteroids = {} local asteroids = {}
local imgs = nil
function asteroids.load(game) function asteroids.load(game)
local imgs = { imgs = {
love.graphics.newImage('assets/sprites/asteroids/1.png'), love.graphics.newImage('assets/sprites/asteroids/asteroid01.png'),
love.graphics.newImage('assets/sprites/asteroids/2.png'), love.graphics.newImage('assets/sprites/asteroids/asteroid02.png'),
love.graphics.newImage('assets/sprites/asteroids/3.png') love.graphics.newImage('assets/sprites/asteroids/asteroid03.png'),
love.graphics.newImage('assets/sprites/asteroids/asteroid04.png')
} }
local num = game.levelaa * 5 asteroids.num = game.level * 5
local max_speed = 5 asteroids.max_speed = 5
-- Generate asteroids -- Generate asteroids
asteroids.bodys = {} asteroids.bodys = {}
for i=1, num do for i = 1, asteroids.num do
local temp_img = imgs[math.random(1, tools.table_length(imgs))] make_asteroid(i, game, true)
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
end end
function asteroids.update(dt, game) function asteroids.update(dt, game)
-- Rotate asteroids -- Rotate asteroids
for key, asteroid in pairs(asteroids.bodys) do for key, asteroid in pairs(asteroids.bodys) do
value.angle = asteroid.angle + (dt * math.pi / 10) asteroid.angle = asteroid.angle + (dt * math.pi / 10)
value.x = asteroid.x - asteroid.speed asteroid.x = asteroid.x - asteroid.speed
end end
-- Destroy asteroids -- Destroy asteroids
for key, asteroid in pairs(asteroids.bodys) do for key, asteroid in pairs(asteroids.bodys) do
if value.x + asteroid.img:getWidth() < 0 then if asteroid.x + asteroid.img:getWidth() < 0 then
table.remove(asteroid, key) table.remove(asteroids.bodys, key)
end end
end end
-- Create asteroids -- Create asteroids
if tools.table_length(asteroids.bodys) < asteroids.num then if tools.table_length(asteroids.bodys) < asteroids.num then
local temp_img = imgs[math.random(1, table_length(imgs))] make_asteroid(tools.table_length(asteroids.bodys) + 1, game, false)
asteroids.bodys[table_length(asteroids.bodys) + 1] = { end
end
function asteroids.draw()
for key, asteroid in pairs(asteroids.bodys) do
love.graphics.draw(asteroid.img, asteroid.x, asteroid.y, asteroid.angle, 1, 1, asteroid.img:getWidth() / 2, asteroid.img:getHeight() / 2)
end
end
function make_asteroid(pos, game, x_random)
local temp_img = imgs[math.random(1, tools.table_length(imgs))]
asteroids.bodys[pos] = {
x = game.canvas.width + temp_img:getWidth(), x = game.canvas.width + temp_img:getWidth(),
y = math.random(game.window.height, game.canvas.height - temp_img:getHeight()), y = math.random(game.window.height / 2, game.canvas.height - temp_img:getHeight()),
speed = math.random(1, max_speed), speed = math.random(1, asteroids.max_speed),
img = temp_img, img = temp_img,
angle = math.random(0, 90)} angle = math.random(0, 90)
}
if x_random then
asteroids.bodys[pos].x = math.random(0, game.canvas.width - temp_img:getWidth())
end end
end end

Binary file not shown.

Before

Width:  |  Height:  |  Size: 571 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 585 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 559 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.7 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.4 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.6 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

View File

@ -16,15 +16,16 @@ end
function love.update(dt) function love.update(dt)
game.world:update(dt) game.world:update(dt)
background.update(dt) background.update(dt)
asteroids.load(dt, game) asteroids.update(dt, game)
controls.update(dt)
spaceship.update(dt) spaceship.update(dt)
controls.update(dt)
end end
-- DRAW -- DRAW
function love.draw() function love.draw()
background.draw() background.draw()
spaceship.draw() spaceship.draw()
asteroids.draw()
end end
-- CONTROLS -- CONTROLS