add spaceship
This commit is contained in:
parent
892d89c7f1
commit
5fb3cd8d47
BIN
android/game.apk
BIN
android/game.apk
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest package="love.to.android1104181206"
|
<manifest package="love.to.android1112134304"
|
||||||
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 1104181206"
|
android:label="Game 1112134304"
|
||||||
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 1104181206"
|
android:label="Game 1112134304"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:screenOrientation="landscape" >
|
android:screenOrientation="landscape" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<manifest package="love.to.android1104181206"
|
<manifest package="love.to.android1112134304"
|
||||||
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 1104181206"
|
android:label="Game 1112134304"
|
||||||
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 1104181206"
|
android:label="Game 1112134304"
|
||||||
android:launchMode="singleTop"
|
android:launchMode="singleTop"
|
||||||
android:screenOrientation="landscape" >
|
android:screenOrientation="landscape" >
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
|
@ -1,2 +1,2 @@
|
|||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/AndroidManifest.xml : \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/AndroidManifest.xml : \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/AndroidManifest.xml \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/AndroidManifest.xml \
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
#Last build type
|
#Last build type
|
||||||
#Fri, 04 Nov 2016 18:12:11 +0100
|
#Sat, 12 Nov 2016 13:43:10 +0100
|
||||||
|
|
||||||
build.last.target=debug
|
build.last.target=debug
|
||||||
|
|
||||||
|
Binary file not shown.
@ -1,31 +1,31 @@
|
|||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes.dex : \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes.dex : \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/love/to/android1104181206/BuildConfig.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112134304/BuildConfig.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/love/to/android1104181206/LtaActivity.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112134304/LtaActivity.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/love/to/android1104181206/R$attr.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112134304/R$attr.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/love/to/android1104181206/R$drawable.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112134304/R$drawable.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/love/to/android1104181206/R.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/love/to/android1112134304/R.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/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/StartGamedev-160604-osx/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/StartGamedev-160604-osx/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 \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$3.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$3.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$4.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$4.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$5.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$5.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$6.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$6.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$SDLCommandHandler.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$SDLCommandHandler.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$ShowTextInputTask.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity$ShowTextInputTask.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLActivity.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLGenericMotionListener_API12.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLGenericMotionListener_API12.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLInputConnection.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLInputConnection.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLJoystickHandler.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLJoystickHandler.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLJoystickHandler_API12$RangeComparator.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLJoystickHandler_API12$RangeComparator.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLJoystickHandler_API12$SDLJoystick.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLJoystickHandler_API12$SDLJoystick.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLJoystickHandler_API12.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLJoystickHandler_API12.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLMain.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLMain.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLSurface$1.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLSurface$1.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLSurface.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/libsdl/app/SDLSurface.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/love2d/android/DownloadActivity.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/love2d/android/DownloadActivity.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/love2d/android/DownloadRequestSettings_API11.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/love2d/android/DownloadRequestSettings_API11.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/love2d/android/DownloadService$1.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/love2d/android/DownloadService$1.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/love2d/android/DownloadService.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/love2d/android/DownloadService.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/love2d/android/GameActivity$1.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/love2d/android/GameActivity$1.class \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes/org/love2d/android/GameActivity.class \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes/org/love2d/android/GameActivity.class \
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -1,11 +1,11 @@
|
|||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/love_android_sdl2-debug-unaligned.apk : \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/love_android_sdl2-debug-unaligned.apk : \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/love_android_sdl2.ap_ \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/love_android_sdl2.ap_ \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/classes.dex \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/classes.dex \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/libs/armeabi/libgnustl_shared.so \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/libs/armeabi/libgnustl_shared.so \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/libs/armeabi/liblove.so \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/libs/armeabi/liblove.so \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/libs/armeabi/libmpg123.so \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/libs/armeabi/libmpg123.so \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/libs/armeabi/libopenal.so \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/libs/armeabi/libopenal.so \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/libs/armeabi-v7a/libgnustl_shared.so \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/libs/armeabi-v7a/libgnustl_shared.so \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/libs/armeabi-v7a/liblove.so \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/libs/armeabi-v7a/liblove.so \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/libs/armeabi-v7a/libmpg123.so \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/libs/armeabi-v7a/libmpg123.so \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/libs/armeabi-v7a/libopenal.so \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/libs/armeabi-v7a/libopenal.so \
|
||||||
|
Binary file not shown.
Binary file not shown.
@ -1,5 +1,5 @@
|
|||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/love_android_sdl2.ap_ \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/love_android_sdl2.ap_ \
|
||||||
: /Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/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/StartGamedev-160604-osx/tools/love-android-sdl2/bin/res/drawable-xxhdpi/ic_launcher.png \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/res/drawable-xxhdpi/ic_launcher.png \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/assets/game.love \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/assets/game.love \
|
||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/bin/AndroidManifest.xml \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/AndroidManifest.xml \
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
# view AndroidManifest.xml #generated:45
|
# view AndroidManifest.xml #generated:45
|
||||||
-keep class love.to.android1104181206.DownloadActivity { <init>(...); }
|
-keep class love.to.android1112134304.DownloadActivity { <init>(...); }
|
||||||
|
|
||||||
# view AndroidManifest.xml #generated:17
|
# view AndroidManifest.xml #generated:17
|
||||||
-keep class love.to.android1104181206.DownloadService { <init>(...); }
|
-keep class love.to.android1112134304.DownloadService { <init>(...); }
|
||||||
|
|
||||||
# view AndroidManifest.xml #generated:18
|
# view AndroidManifest.xml #generated:18
|
||||||
-keep class love.to.android1104181206.LtaActivity { <init>(...); }
|
-keep class love.to.android1112134304.LtaActivity { <init>(...); }
|
||||||
|
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
/Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/tools/love-android-sdl2/gen/love/to/android1104181206/R.java \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/gen/love/to/android1112134304/R.java \
|
||||||
: /Users/androsfenollosa/www/alunizaje/StartGamedev-160604-osx/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/StartGamedev-160604-osx/tools/love-android-sdl2/bin/AndroidManifest.xml \
|
/Users/androsfenollosa/www/alunizaje/android/tools/love-android-sdl2/bin/AndroidManifest.xml \
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
/** Automatically generated file. DO NOT MODIFY */
|
/** Automatically generated file. DO NOT MODIFY */
|
||||||
package love.to.android1104181206;
|
package love.to.android1112134304;
|
||||||
|
|
||||||
public final class BuildConfig {
|
public final class BuildConfig {
|
||||||
public final static boolean DEBUG = true;
|
public final static boolean DEBUG = true;
|
@ -5,7 +5,7 @@
|
|||||||
* should not be modified by hand.
|
* should not be modified by hand.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
package love.to.android1104181206;
|
package love.to.android1112134304;
|
||||||
|
|
||||||
public final class R {
|
public final class R {
|
||||||
public static final class attr {
|
public static final class attr {
|
@ -1,4 +1,4 @@
|
|||||||
package love.to.android1104181206;
|
package love.to.android1112134304;
|
||||||
import org.love2d.android.GameActivity;
|
import org.love2d.android.GameActivity;
|
||||||
|
|
||||||
public class LtaActivity extends GameActivity {}
|
public class LtaActivity extends GameActivity {}
|
2
assets/scripts/camera.lua
Normal file
2
assets/scripts/camera.lua
Normal file
@ -0,0 +1,2 @@
|
|||||||
|
local cam = gamera.new(0,0,2000,2000)
|
||||||
|
cam:setWorld(0,0,2000,2000)
|
33
assets/scripts/controls.lua
Normal file
33
assets/scripts/controls.lua
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
local controls = {}
|
||||||
|
|
||||||
|
function controls.update(dt)
|
||||||
|
control_up, control_right, control_left, control_quit = false, false, false, false
|
||||||
|
-- Keyboard
|
||||||
|
if love.keyboard.isDown('escape') or love.keyboard.isDown('q') then
|
||||||
|
control_quit = true
|
||||||
|
end
|
||||||
|
if love.keyboard.isDown('right') then
|
||||||
|
control_right = true
|
||||||
|
elseif love.keyboard.isDown('left') then
|
||||||
|
control_left = true
|
||||||
|
end
|
||||||
|
if love.keyboard.isDown('up') then
|
||||||
|
control_up = true
|
||||||
|
end
|
||||||
|
-- Mouse
|
||||||
|
if love.mouse.isDown(1) then
|
||||||
|
local x, y = love.mouse.getPosition()
|
||||||
|
-- Up
|
||||||
|
if x > button_up.x and x < button_up.x + button.img:getWidth() and y > button_up.y + camera.y and y < button_up.y + button.img:getHeight() + camera.y then
|
||||||
|
control_up = true
|
||||||
|
end
|
||||||
|
-- Right
|
||||||
|
if x > button_right.x and x < button_right.x + button.img:getWidth() and y > button_right.y + camera.y and y < button_right.y + button.img:getHeight() + camera.y then
|
||||||
|
control_right = true
|
||||||
|
elseif x > button_left.x and x < button_left.x + button.img:getWidth() and y > button_left.y + camera.y and y < button_left.y + button.img:getHeight() + camera.y then
|
||||||
|
control_left = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return controls
|
39
assets/scripts/spaceship.lua
Normal file
39
assets/scripts/spaceship.lua
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
local anim8 = require 'assets/scripts/vendor/anim8'
|
||||||
|
|
||||||
|
local spaceship = {}
|
||||||
|
|
||||||
|
function spaceship.load(world)
|
||||||
|
local canvas = {}
|
||||||
|
canvas.width = 500
|
||||||
|
-- power origin 1000
|
||||||
|
spaceship = { x = 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.shape = love.physics.newCircleShape(20)
|
||||||
|
spaceship.fixture = love.physics.newFixture(spaceship.body, spaceship.shape, 1)
|
||||||
|
spaceship.fixture:setRestitution(0.9)
|
||||||
|
local g = anim8.newGrid(98, 93, spaceship.img:getWidth(), spaceship.img:getHeight())
|
||||||
|
spaceship.animation = anim8.newAnimation(g('1-1', 1), 0.1)
|
||||||
|
end
|
||||||
|
|
||||||
|
function spaceship.update(dt)
|
||||||
|
spaceship.animation:update(dt)
|
||||||
|
-- Controls
|
||||||
|
if control_up then
|
||||||
|
spaceship.body:applyForce(0, -spaceship.power)
|
||||||
|
end
|
||||||
|
if control_right then
|
||||||
|
spaceship.body:applyForce(spaceship.power, 0)
|
||||||
|
elseif control_left then
|
||||||
|
spaceship.body:applyForce(-spaceship.power, 0)
|
||||||
|
end
|
||||||
|
if control_quit then
|
||||||
|
love.event.push('quit')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
function spaceship.draw()
|
||||||
|
spaceship.animation:draw(spaceship.img, spaceship.body:getX(), spaceship.body:getY())
|
||||||
|
end
|
||||||
|
|
||||||
|
return spaceship
|
302
assets/scripts/vendor/anim8.lua
vendored
Normal file
302
assets/scripts/vendor/anim8.lua
vendored
Normal file
@ -0,0 +1,302 @@
|
|||||||
|
local anim8 = {
|
||||||
|
_VERSION = 'anim8 v2.3.0',
|
||||||
|
_DESCRIPTION = 'An animation library for LÖVE',
|
||||||
|
_URL = 'https://github.com/kikito/anim8',
|
||||||
|
_LICENSE = [[
|
||||||
|
MIT LICENSE
|
||||||
|
|
||||||
|
Copyright (c) 2011 Enrique García Cota
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a
|
||||||
|
copy of this software and associated documentation files (the
|
||||||
|
"Software"), to deal in the Software without restriction, including
|
||||||
|
without limitation the rights to use, copy, modify, merge, publish,
|
||||||
|
distribute, sublicense, and/or sell copies of the Software, and to
|
||||||
|
permit persons to whom the Software is furnished to do so, subject to
|
||||||
|
the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included
|
||||||
|
in all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
|
||||||
|
OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
||||||
|
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
||||||
|
IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
||||||
|
CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
||||||
|
TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
||||||
|
SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
]]
|
||||||
|
}
|
||||||
|
|
||||||
|
local Grid = {}
|
||||||
|
|
||||||
|
local _frames = {}
|
||||||
|
|
||||||
|
local function assertPositiveInteger(value, name)
|
||||||
|
if type(value) ~= 'number' then error(("%s should be a number, was %q"):format(name, tostring(value))) end
|
||||||
|
if value < 1 then error(("%s should be a positive number, was %d"):format(name, value)) end
|
||||||
|
if value ~= math.floor(value) then error(("%s should be an integer, was %d"):format(name, value)) end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function createFrame(self, x, y)
|
||||||
|
local fw, fh = self.frameWidth, self.frameHeight
|
||||||
|
return love.graphics.newQuad(
|
||||||
|
self.left + (x-1) * fw + x * self.border,
|
||||||
|
self.top + (y-1) * fh + y * self.border,
|
||||||
|
fw,
|
||||||
|
fh,
|
||||||
|
self.imageWidth,
|
||||||
|
self.imageHeight
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getGridKey(...)
|
||||||
|
return table.concat( {...} ,'-' )
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getOrCreateFrame(self, x, y)
|
||||||
|
if x < 1 or x > self.width or y < 1 or y > self.height then
|
||||||
|
error(("There is no frame for x=%d, y=%d"):format(x, y))
|
||||||
|
end
|
||||||
|
local key = self._key
|
||||||
|
_frames[key] = _frames[key] or {}
|
||||||
|
_frames[key][x] = _frames[key][x] or {}
|
||||||
|
_frames[key][x][y] = _frames[key][x][y] or createFrame(self, x, y)
|
||||||
|
return _frames[key][x][y]
|
||||||
|
end
|
||||||
|
|
||||||
|
local function parseInterval(str)
|
||||||
|
if type(str) == "number" then return str,str,1 end
|
||||||
|
str = str:gsub('%s', '') -- remove spaces
|
||||||
|
local min, max = str:match("^(%d+)-(%d+)$")
|
||||||
|
assert(min and max, ("Could not parse interval from %q"):format(str))
|
||||||
|
min, max = tonumber(min), tonumber(max)
|
||||||
|
local step = min <= max and 1 or -1
|
||||||
|
return min, max, step
|
||||||
|
end
|
||||||
|
|
||||||
|
function Grid:getFrames(...)
|
||||||
|
local result, args = {}, {...}
|
||||||
|
local minx, maxx, stepx, miny, maxy, stepy
|
||||||
|
|
||||||
|
for i=1, #args, 2 do
|
||||||
|
minx, maxx, stepx = parseInterval(args[i])
|
||||||
|
miny, maxy, stepy = parseInterval(args[i+1])
|
||||||
|
for y = miny, maxy, stepy do
|
||||||
|
for x = minx, maxx, stepx do
|
||||||
|
result[#result+1] = getOrCreateFrame(self,x,y)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local Gridmt = {
|
||||||
|
__index = Grid,
|
||||||
|
__call = Grid.getFrames
|
||||||
|
}
|
||||||
|
|
||||||
|
local function newGrid(frameWidth, frameHeight, imageWidth, imageHeight, left, top, border)
|
||||||
|
assertPositiveInteger(frameWidth, "frameWidth")
|
||||||
|
assertPositiveInteger(frameHeight, "frameHeight")
|
||||||
|
assertPositiveInteger(imageWidth, "imageWidth")
|
||||||
|
assertPositiveInteger(imageHeight, "imageHeight")
|
||||||
|
|
||||||
|
left = left or 0
|
||||||
|
top = top or 0
|
||||||
|
border = border or 0
|
||||||
|
|
||||||
|
local key = getGridKey(frameWidth, frameHeight, imageWidth, imageHeight, left, top, border)
|
||||||
|
|
||||||
|
local grid = setmetatable(
|
||||||
|
{ frameWidth = frameWidth,
|
||||||
|
frameHeight = frameHeight,
|
||||||
|
imageWidth = imageWidth,
|
||||||
|
imageHeight = imageHeight,
|
||||||
|
left = left,
|
||||||
|
top = top,
|
||||||
|
border = border,
|
||||||
|
width = math.floor(imageWidth/frameWidth),
|
||||||
|
height = math.floor(imageHeight/frameHeight),
|
||||||
|
_key = key
|
||||||
|
},
|
||||||
|
Gridmt
|
||||||
|
)
|
||||||
|
return grid
|
||||||
|
end
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
local Animation = {}
|
||||||
|
|
||||||
|
local function cloneArray(arr)
|
||||||
|
local result = {}
|
||||||
|
for i=1,#arr do result[i] = arr[i] end
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local function parseDurations(durations, frameCount)
|
||||||
|
local result = {}
|
||||||
|
if type(durations) == 'number' then
|
||||||
|
for i=1,frameCount do result[i] = durations end
|
||||||
|
else
|
||||||
|
local min, max, step
|
||||||
|
for key,duration in pairs(durations) do
|
||||||
|
assert(type(duration) == 'number', "The value [" .. tostring(duration) .. "] should be a number")
|
||||||
|
min, max, step = parseInterval(key)
|
||||||
|
for i = min,max,step do result[i] = duration end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
if #result < frameCount then
|
||||||
|
error("The durations table has length of " .. tostring(#result) .. ", but it should be >= " .. tostring(frameCount))
|
||||||
|
end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local function parseIntervals(durations)
|
||||||
|
local result, time = {0},0
|
||||||
|
for i=1,#durations do
|
||||||
|
time = time + durations[i]
|
||||||
|
result[i+1] = time
|
||||||
|
end
|
||||||
|
return result, time
|
||||||
|
end
|
||||||
|
|
||||||
|
local Animationmt = { __index = Animation }
|
||||||
|
local nop = function() end
|
||||||
|
|
||||||
|
local function newAnimation(frames, durations, onLoop)
|
||||||
|
local td = type(durations);
|
||||||
|
if (td ~= 'number' or durations <= 0) and td ~= 'table' then
|
||||||
|
error("durations must be a positive number. Was " .. tostring(durations) )
|
||||||
|
end
|
||||||
|
onLoop = onLoop or nop
|
||||||
|
durations = parseDurations(durations, #frames)
|
||||||
|
local intervals, totalDuration = parseIntervals(durations)
|
||||||
|
return setmetatable({
|
||||||
|
frames = cloneArray(frames),
|
||||||
|
durations = durations,
|
||||||
|
intervals = intervals,
|
||||||
|
totalDuration = totalDuration,
|
||||||
|
onLoop = onLoop,
|
||||||
|
timer = 0,
|
||||||
|
position = 1,
|
||||||
|
status = "playing",
|
||||||
|
flippedH = false,
|
||||||
|
flippedV = false
|
||||||
|
},
|
||||||
|
Animationmt
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:clone()
|
||||||
|
local newAnim = newAnimation(self.frames, self.durations, self.onLoop)
|
||||||
|
newAnim.flippedH, newAnim.flippedV = self.flippedH, self.flippedV
|
||||||
|
return newAnim
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:flipH()
|
||||||
|
self.flippedH = not self.flippedH
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:flipV()
|
||||||
|
self.flippedV = not self.flippedV
|
||||||
|
return self
|
||||||
|
end
|
||||||
|
|
||||||
|
local function seekFrameIndex(intervals, timer)
|
||||||
|
local high, low, i = #intervals-1, 1, 1
|
||||||
|
|
||||||
|
while(low <= high) do
|
||||||
|
i = math.floor((low + high) / 2)
|
||||||
|
if timer > intervals[i+1] then low = i + 1
|
||||||
|
elseif timer <= intervals[i] then high = i - 1
|
||||||
|
else
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
return i
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:update(dt)
|
||||||
|
if self.status ~= "playing" then return end
|
||||||
|
|
||||||
|
self.timer = self.timer + dt
|
||||||
|
local loops = math.floor(self.timer / self.totalDuration)
|
||||||
|
if loops ~= 0 then
|
||||||
|
self.timer = self.timer - self.totalDuration * loops
|
||||||
|
local f = type(self.onLoop) == 'function' and self.onLoop or self[self.onLoop]
|
||||||
|
f(self, loops)
|
||||||
|
end
|
||||||
|
|
||||||
|
self.position = seekFrameIndex(self.intervals, self.timer)
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:pause()
|
||||||
|
self.status = "paused"
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:gotoFrame(position)
|
||||||
|
self.position = position
|
||||||
|
self.timer = self.intervals[self.position]
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:pauseAtEnd()
|
||||||
|
self.position = #self.frames
|
||||||
|
self.timer = self.totalDuration
|
||||||
|
self:pause()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:pauseAtStart()
|
||||||
|
self.position = 1
|
||||||
|
self.timer = 0
|
||||||
|
self:pause()
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:resume()
|
||||||
|
self.status = "playing"
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:draw(image, x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
love.graphics.draw(image, self:getFrameInfo(x, y, r, sx, sy, ox, oy, kx, ky))
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:getFrameInfo(x, y, r, sx, sy, ox, oy, kx, ky)
|
||||||
|
local frame = self.frames[self.position]
|
||||||
|
if self.flippedH or self.flippedV then
|
||||||
|
r,sx,sy,ox,oy,kx,ky = r or 0, sx or 1, sy or 1, ox or 0, oy or 0, kx or 0, ky or 0
|
||||||
|
local _,_,w,h = frame:getViewport()
|
||||||
|
|
||||||
|
if self.flippedH then
|
||||||
|
sx = sx * -1
|
||||||
|
ox = w - ox
|
||||||
|
kx = kx * -1
|
||||||
|
ky = ky * -1
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.flippedV then
|
||||||
|
sy = sy * -1
|
||||||
|
oy = h - oy
|
||||||
|
kx = kx * -1
|
||||||
|
ky = ky * -1
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return frame, x, y, r, sx, sy, ox, oy, kx, ky
|
||||||
|
end
|
||||||
|
|
||||||
|
function Animation:getDimensions()
|
||||||
|
local _,_,w,h = self.frames[self.position]:getViewport()
|
||||||
|
return w,h
|
||||||
|
end
|
||||||
|
|
||||||
|
-----------------------------------------------------------
|
||||||
|
|
||||||
|
anim8.newGrid = newGrid
|
||||||
|
anim8.newAnimation = newAnimation
|
||||||
|
|
||||||
|
return anim8
|
208
assets/scripts/vendor/gamera.lua
vendored
Normal file
208
assets/scripts/vendor/gamera.lua
vendored
Normal file
@ -0,0 +1,208 @@
|
|||||||
|
-- gamera.lua v1.0.1
|
||||||
|
|
||||||
|
-- Copyright (c) 2012 Enrique García Cota
|
||||||
|
-- Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
|
||||||
|
-- The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
|
||||||
|
-- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||||
|
-- Based on YaciCode, from Julien Patte and LuaObject, from Sebastien Rocca-Serra
|
||||||
|
|
||||||
|
local gamera = {}
|
||||||
|
|
||||||
|
-- Private attributes and methods
|
||||||
|
|
||||||
|
local gameraMt = {__index = gamera}
|
||||||
|
local abs, min, max = math.abs, math.min, math.max
|
||||||
|
|
||||||
|
local function clamp(x, minX, maxX)
|
||||||
|
return x < minX and minX or (x>maxX and maxX or x)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function checkNumber(value, name)
|
||||||
|
if type(value) ~= 'number' then
|
||||||
|
error(name .. " must be a number (was: " .. tostring(value) .. ")")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function checkPositiveNumber(value, name)
|
||||||
|
if type(value) ~= 'number' or value <=0 then
|
||||||
|
error(name .. " must be a positive number (was: " .. tostring(value) ..")")
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local function checkAABB(l,t,w,h)
|
||||||
|
checkNumber(l, "l")
|
||||||
|
checkNumber(t, "t")
|
||||||
|
checkPositiveNumber(w, "w")
|
||||||
|
checkPositiveNumber(h, "h")
|
||||||
|
end
|
||||||
|
|
||||||
|
local function getVisibleArea(self, scale)
|
||||||
|
scale = scale or self.scale
|
||||||
|
local sin, cos = abs(self.sin), abs(self.cos)
|
||||||
|
local w,h = self.w / scale, self.h / scale
|
||||||
|
w,h = cos*w + sin*h, sin*w + cos*h
|
||||||
|
return min(w,self.ww), min(h, self.wh)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function cornerTransform(self, x,y)
|
||||||
|
local scale, sin, cos = self.scale, self.sin, self.cos
|
||||||
|
x,y = x - self.x, y - self.y
|
||||||
|
x,y = -cos*x + sin*y, -sin*x - cos*y
|
||||||
|
return self.x - (x/scale + self.l), self.y - (y/scale + self.t)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function adjustPosition(self)
|
||||||
|
local wl,wt,ww,wh = self.wl, self.wt, self.ww, self.wh
|
||||||
|
local w,h = getVisibleArea(self)
|
||||||
|
local w2,h2 = w*0.5, h*0.5
|
||||||
|
|
||||||
|
local left, right = wl + w2, wl + ww - w2
|
||||||
|
local top, bottom = wt + h2, wt + wh - h2
|
||||||
|
|
||||||
|
self.x, self.y = clamp(self.x, left, right), clamp(self.y, top, bottom)
|
||||||
|
end
|
||||||
|
|
||||||
|
local function adjustScale(self)
|
||||||
|
local w,h,ww,wh = self.w, self.h, self.ww, self.wh
|
||||||
|
local rw,rh = getVisibleArea(self, 1) -- rotated frame: area around the window, rotated without scaling
|
||||||
|
local sx,sy = rw/ww, rh/wh -- vert/horiz scale: minimun scales that the window needs to occupy the world
|
||||||
|
local rscale = max(sx,sy)
|
||||||
|
|
||||||
|
self.scale = max(self.scale, rscale)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Public interface
|
||||||
|
|
||||||
|
function gamera.new(l,t,w,h)
|
||||||
|
|
||||||
|
local sw,sh = love.graphics.getWidth(), love.graphics.getHeight()
|
||||||
|
|
||||||
|
local cam = setmetatable({
|
||||||
|
x=0, y=0,
|
||||||
|
scale=1,
|
||||||
|
angle=0, sin=math.sin(0), cos=math.cos(0),
|
||||||
|
l=0, t=0, w=sw, h=sh, w2=sw*0.5, h2=sh*0.5
|
||||||
|
}, gameraMt)
|
||||||
|
|
||||||
|
cam:setWorld(l,t,w,h)
|
||||||
|
|
||||||
|
return cam
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:setWorld(l,t,w,h)
|
||||||
|
checkAABB(l,t,w,h)
|
||||||
|
|
||||||
|
self.wl, self.wt, self.ww, self.wh = l,t,w,h
|
||||||
|
|
||||||
|
adjustPosition(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:setWindow(l,t,w,h)
|
||||||
|
checkAABB(l,t,w,h)
|
||||||
|
|
||||||
|
self.l, self.t, self.w, self.h, self.w2, self.h2 = l,t,w,h, w*0.5, h*0.5
|
||||||
|
|
||||||
|
adjustPosition(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:setPosition(x,y)
|
||||||
|
checkNumber(x, "x")
|
||||||
|
checkNumber(y, "y")
|
||||||
|
|
||||||
|
self.x, self.y = x,y
|
||||||
|
|
||||||
|
adjustPosition(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:setScale(scale)
|
||||||
|
checkNumber(scale, "scale")
|
||||||
|
|
||||||
|
self.scale = scale
|
||||||
|
|
||||||
|
adjustScale(self)
|
||||||
|
adjustPosition(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:setAngle(angle)
|
||||||
|
checkNumber(angle, "angle")
|
||||||
|
|
||||||
|
self.angle = angle
|
||||||
|
self.cos, self.sin = math.cos(angle), math.sin(angle)
|
||||||
|
|
||||||
|
adjustScale(self)
|
||||||
|
adjustPosition(self)
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:getWorld()
|
||||||
|
return self.wl, self.wt, self.ww, self.wh
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:getWindow()
|
||||||
|
return self.l, self.t, self.w, self.h
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:getPosition()
|
||||||
|
return self.x, self.y
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:getScale()
|
||||||
|
return self.scale
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:getAngle()
|
||||||
|
return self.angle
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:getVisible()
|
||||||
|
local w,h = getVisibleArea(self)
|
||||||
|
return self.x - w*0.5, self.y - h*0.5, w, h
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:getVisibleCorners()
|
||||||
|
local x,y,w2,h2 = self.x, self.y, self.w2, self.h2
|
||||||
|
|
||||||
|
local x1,y1 = cornerTransform(self, x-w2,y-h2)
|
||||||
|
local x2,y2 = cornerTransform(self, x+w2,y-h2)
|
||||||
|
local x3,y3 = cornerTransform(self, x+w2,y+h2)
|
||||||
|
local x4,y4 = cornerTransform(self, x-w2,y+h2)
|
||||||
|
|
||||||
|
return x1,y1,x2,y2,x3,y3,x4,y4
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:draw(f)
|
||||||
|
love.graphics.setScissor(self:getWindow())
|
||||||
|
|
||||||
|
love.graphics.push()
|
||||||
|
local scale = self.scale
|
||||||
|
love.graphics.scale(scale)
|
||||||
|
|
||||||
|
love.graphics.translate((self.w2 + self.l) / scale, (self.h2+self.t) / scale)
|
||||||
|
love.graphics.rotate(-self.angle)
|
||||||
|
love.graphics.translate(-self.x, -self.y)
|
||||||
|
|
||||||
|
f(self:getVisible())
|
||||||
|
|
||||||
|
love.graphics.pop()
|
||||||
|
|
||||||
|
love.graphics.setScissor()
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:toWorld(x,y)
|
||||||
|
local scale, sin, cos = self.scale, self.sin, self.cos
|
||||||
|
x,y = (x - self.w2 - self.l) / scale, (y - self.h2 - self.t) / scale
|
||||||
|
x,y = cos*x - sin*y, sin*x + cos*y
|
||||||
|
return x + self.x, y + self.y
|
||||||
|
end
|
||||||
|
|
||||||
|
function gamera:toScreen(x,y)
|
||||||
|
local scale, sin, cos = self.scale, self.sin, self.cos
|
||||||
|
x,y = x - self.x, y - self.y
|
||||||
|
x,y = cos*x + sin*y, -sin*x + cos*y
|
||||||
|
return scale * x + self.w2 + self.l, scale * y + self.h2 + self.t
|
||||||
|
end
|
||||||
|
|
||||||
|
return gamera
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
388
main.lua
388
main.lua
@ -1,397 +1,39 @@
|
|||||||
local start_time = 0
|
local spaceship = require 'assets/scripts/spaceship'
|
||||||
|
local controls = require 'assets/scripts/controls'
|
||||||
|
|
||||||
-- LOAD
|
-- LOAD
|
||||||
function love.load()
|
function love.load()
|
||||||
-- Configuration
|
-- Configuration
|
||||||
math.randomseed(os.time())
|
math.randomseed(os.time())
|
||||||
width, height = love.window.getDesktopDimensions( display )
|
local width, height = love.window.getDesktopDimensions( display )
|
||||||
window = { width = width , height = height }
|
window = { width = width , height = height }
|
||||||
fullscreen = false
|
love.window.setMode(window.width, window.height)
|
||||||
love.window.setMode(window.width, window.height, {resizable=true})
|
|
||||||
font_main = love.graphics.newFont('assets/fonts/main.ttf', 80) -- Font
|
|
||||||
love.graphics.setFont(font_main)
|
|
||||||
text_restart = { text = 'You die' }
|
|
||||||
text_restart.size = font_main:getWidth(text_restart.text)
|
|
||||||
text_good = { text = 'Good' }
|
|
||||||
text_good.size = font_main:getWidth(text_good.text)
|
|
||||||
camera = { x = 0, y = 0, width = window.width, height = window.height }
|
|
||||||
debug = false
|
|
||||||
play = true
|
|
||||||
win = false
|
|
||||||
level = { num = 1, x = 50, y = 50, max = 20 }
|
|
||||||
love.window.setFullscreen(fullscreen, 'exclusive')
|
|
||||||
love.window.setTitle('Alunizaje')
|
|
||||||
background = { x = 0, y = 0, img = love.graphics.newImage('assets/sprites/background/background.png') }
|
|
||||||
canvas = { width = width, height = 2880 }
|
|
||||||
moon_margin = 100
|
|
||||||
-- Physics
|
-- Physics
|
||||||
world_meter = 64
|
world_meter = 64
|
||||||
gravity = 2
|
gravity = 2
|
||||||
love.physics.setMeter(world_meter) -- Height earth in meters
|
love.physics.setMeter(world_meter) -- Height earth in meters
|
||||||
world = love.physics.newWorld(0, gravity * world_meter, true) -- Make earth
|
world = love.physics.newWorld(0, gravity * world_meter, true) -- Make earth
|
||||||
-- Ship
|
-- Spaceship
|
||||||
ship = { x = canvas.width / 2, y = 0 , power = 1000 , size_collition = 28, polygons_collition = 8 }
|
spaceship.load(world)
|
||||||
ship.img = love.graphics.newImage('assets/sprites/spaceship/body.png')
|
|
||||||
ship.body = love.physics.newBody(world, (canvas.width / 2) - (ship.img:getWidth() / 2) , ship.y, 'dynamic')
|
|
||||||
ship.shape = love.physics.newCircleShape(20)
|
|
||||||
ship.fixture = love.physics.newFixture(ship.body, ship.shape, 1)
|
|
||||||
ship.fixture:setRestitution(0.9)
|
|
||||||
ship.time_start = 1
|
|
||||||
start_time = 0
|
|
||||||
-- Fire
|
|
||||||
fire = {}
|
|
||||||
fire.img = love.graphics.newImage('assets/sprites/spaceship/fire.png')
|
|
||||||
fire.num_frames = 4
|
|
||||||
fire.pos_frame = 0
|
|
||||||
fire.visible = false
|
|
||||||
fire.distance_ship = 10
|
|
||||||
fire.frame_width = fire.img:getWidth() / fire.num_frames
|
|
||||||
fire.frames = {
|
|
||||||
love.graphics.newQuad(fire.frame_width * 0, 0, fire.frame_width, fire.frame_width, fire.img:getWidth(), fire.img:getHeight()),
|
|
||||||
love.graphics.newQuad(fire.frame_width * 1, 0, fire.frame_width, fire.frame_width, fire.img:getWidth(), fire.img:getHeight()),
|
|
||||||
love.graphics.newQuad(fire.frame_width * 2, 0, fire.frame_width, fire.frame_width, fire.img:getWidth(), fire.img:getHeight()),
|
|
||||||
love.graphics.newQuad(fire.frame_width * 3, 0, fire.frame_width, fire.frame_width, fire.img:getWidth(), fire.img:getHeight())
|
|
||||||
}
|
|
||||||
-- Explosion
|
|
||||||
explosion = {}
|
|
||||||
explosion.img = love.graphics.newImage('assets/sprites/spaceship/explosion.png')
|
|
||||||
explosion.num_frames = 11
|
|
||||||
explosion.pos_frame = 1
|
|
||||||
explosion.active = false
|
|
||||||
explosion.finish = false
|
|
||||||
explosion.time = 0
|
|
||||||
explosion.speed = 0.05
|
|
||||||
explosion.frame_width = explosion.img:getWidth() / explosion.num_frames
|
|
||||||
explosion.frame_height = explosion.img:getHeight()
|
|
||||||
explosion.frames = {
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 0, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 1, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 2, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 3, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 4, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 5, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 6, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 7, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 8, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 9, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
|
||||||
love.graphics.newQuad(explosion.frame_width * 10, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight())
|
|
||||||
}
|
|
||||||
|
|
||||||
-- Button
|
|
||||||
control_up, control_right, control_left, control_quit = false, false, false, false
|
|
||||||
button = {}
|
|
||||||
button.img = love.graphics.newImage('assets/sprites/hui/button.png')
|
|
||||||
button.num_frames = 2
|
|
||||||
button.frame_width = button.img:getWidth() / button.num_frames
|
|
||||||
button.frame_height = button.img:getHeight()
|
|
||||||
button.frames = {
|
|
||||||
love.graphics.newQuad(button.frame_width * 0, 0, button.frame_width, button.frame_height, button.img:getWidth(), button.img:getHeight()),
|
|
||||||
love.graphics.newQuad(button.frame_width * 1, 0, button.frame_width, button.frame_height, button.img:getWidth(), button.img:getHeight())
|
|
||||||
}
|
|
||||||
button_up = {}
|
|
||||||
button_up.x = window.width - (button.img:getWidth() / button.num_frames) - (button.img:getWidth() / (2 * button.num_frames))
|
|
||||||
button_up.y = level.y + (camera.height / 4) + -camera.y
|
|
||||||
button_right = {}
|
|
||||||
button_right.x = button_up.x
|
|
||||||
button_right.y = button_up.y + (button.img:getHeight() / 3)
|
|
||||||
button_left = {}
|
|
||||||
button_left.x = button.img:getWidth() / (2 * button.num_frames)
|
|
||||||
button_left.y = button_right.y
|
|
||||||
-- Generates initial asteroids
|
|
||||||
asteroids_collision = 40
|
|
||||||
asteroids_collision_polygon = 8
|
|
||||||
max_speed_asteroids = 5
|
|
||||||
img_asteroide = {
|
|
||||||
love.graphics.newImage('assets/sprites/asteroids/1.png'),
|
|
||||||
love.graphics.newImage('assets/sprites/asteroids/2.png'),
|
|
||||||
love.graphics.newImage('assets/sprites/asteroids/3.png')
|
|
||||||
}
|
|
||||||
-- Audios
|
|
||||||
sounds = {}
|
|
||||||
sounds.die = love.audio.newSource('assets/audios/sound/die.wav', 'static')
|
|
||||||
sounds.explosion = love.audio.newSource('assets/audios/sound/explosion_bit.wav', 'static')
|
|
||||||
sounds.ambient_1 = love.audio.newSource('assets/audios/sound/ambient_1.wav')
|
|
||||||
sounds.complete = love.audio.newSource('assets/audios/sound/complete.wav')
|
|
||||||
sounds.fire = love.audio.newSource('assets/audios/sound/fire.wav', 'static')
|
|
||||||
sounds.ambient_1:setLooping(true)
|
|
||||||
sounds.ambient_1:play()
|
|
||||||
|
|
||||||
restart(level.num)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- UPDATE
|
-- UPDATE
|
||||||
function love.update(dt)
|
function love.update(dt)
|
||||||
-- Fix position ship
|
world:update(dt)
|
||||||
if ship.y < 0 then
|
controls.update(dt)
|
||||||
ship.y = 0
|
spaceship.update(dt)
|
||||||
end
|
|
||||||
-- Count time
|
|
||||||
start_time = dt + start_time
|
|
||||||
-- Sprite
|
|
||||||
if not explosion.finish and explosion.active then -- Explosion
|
|
||||||
explosion.time = explosion.time + dt
|
|
||||||
if explosion.time > explosion.speed then
|
|
||||||
explosion.pos_frame = explosion.pos_frame + 1
|
|
||||||
explosion.time = 0
|
|
||||||
end
|
|
||||||
if explosion.pos_frame > explosion.num_frames then
|
|
||||||
sleep(1)
|
|
||||||
restart(level.num)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Restart
|
|
||||||
if not explosion.active and not play then
|
|
||||||
sleep(3)
|
|
||||||
restart(level.num)
|
|
||||||
end
|
|
||||||
if play then
|
|
||||||
-- Phytics world
|
|
||||||
world:update(dt)
|
|
||||||
-- Sprite
|
|
||||||
fire.visible = false
|
|
||||||
if fire.pos_frame < fire.num_frames then -- Fire
|
|
||||||
fire.pos_frame = fire.pos_frame + 1
|
|
||||||
else
|
|
||||||
fire.pos_frame = 1
|
|
||||||
end
|
|
||||||
-- Controls
|
|
||||||
control_up, control_right, control_left, control_quit = false, false, false, false
|
|
||||||
-- Keyboard
|
|
||||||
if love.keyboard.isDown('escape') or love.keyboard.isDown('q') then
|
|
||||||
control_quit = true
|
|
||||||
end
|
|
||||||
if love.keyboard.isDown('right') then
|
|
||||||
control_right = true
|
|
||||||
elseif love.keyboard.isDown('left') then
|
|
||||||
control_left = true
|
|
||||||
end
|
|
||||||
if love.keyboard.isDown('up') then
|
|
||||||
control_up = true
|
|
||||||
end
|
|
||||||
-- Mouse
|
|
||||||
if love.mouse.isDown(1) then
|
|
||||||
local x, y = love.mouse.getPosition()
|
|
||||||
-- Up
|
|
||||||
if x > button_up.x and x < button_up.x + button.img:getWidth() and y > button_up.y + camera.y and y < button_up.y + button.img:getHeight() + camera.y then
|
|
||||||
control_up = true
|
|
||||||
end
|
|
||||||
-- Right
|
|
||||||
if x > button_right.x and x < button_right.x + button.img:getWidth() and y > button_right.y + camera.y and y < button_right.y + button.img:getHeight() + camera.y then
|
|
||||||
control_right = true
|
|
||||||
elseif x > button_left.x and x < button_left.x + button.img:getWidth() and y > button_left.y + camera.y and y < button_left.y + button.img:getHeight() + camera.y then
|
|
||||||
control_left = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Ship move
|
|
||||||
if control_up then
|
|
||||||
ship.body:applyForce(0, -ship.power)
|
|
||||||
fire.visible = true
|
|
||||||
sounds.fire:play()
|
|
||||||
end
|
|
||||||
if control_right then
|
|
||||||
ship.body:applyForce(ship.power, 0)
|
|
||||||
fire.visible = true
|
|
||||||
sounds.fire:play()
|
|
||||||
elseif control_left then
|
|
||||||
ship.body:applyForce(-ship.power, 0)
|
|
||||||
fire.visible = true
|
|
||||||
sounds.fire:play()
|
|
||||||
end
|
|
||||||
if control_quit then
|
|
||||||
love.event.push('quit')
|
|
||||||
end
|
|
||||||
-- Rotate asteroids
|
|
||||||
for key, value in pairs(asteroids) do
|
|
||||||
value.angle = asteroids[key].angle + (dt * math.pi / 10)
|
|
||||||
value.x = asteroids[key].x - asteroids[key].speed
|
|
||||||
end
|
|
||||||
-- Destroy asteroids
|
|
||||||
for key, value in pairs(asteroids) do
|
|
||||||
if value.x + asteroids[key].img:getWidth() < 0 then
|
|
||||||
table.remove(asteroids, key)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Create asteroids
|
|
||||||
if table_length(asteroids) < num_asteroids then
|
|
||||||
local temp_img = img_asteroide[math.random(1, table_length(img_asteroide))]
|
|
||||||
asteroids[table_length(asteroids) + 1] = {
|
|
||||||
x = canvas.width + temp_img:getWidth(),
|
|
||||||
y = math.random(window.height, canvas.height - temp_img:getHeight()),
|
|
||||||
speed = math.random(1, max_speed_asteroids),
|
|
||||||
img = temp_img,
|
|
||||||
angle = math.random(0, 90)}
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Camera
|
|
||||||
camera.y = 0
|
|
||||||
if camera.height / 3 <= ship.body:getY() then -- Top
|
|
||||||
camera.y = -ship.body:getY() + (camera.height / 3)
|
|
||||||
end
|
|
||||||
if canvas.height - ((camera.height / 3) * 2) < ship.body:getY() then -- Down
|
|
||||||
camera.y = -canvas.height + camera.height
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Collision
|
|
||||||
if ship.body:getY() <= 0 then -- Top game
|
|
||||||
x, y = ship.body:getLinearVelocity()
|
|
||||||
ship.body:setLinearVelocity(x, -y)
|
|
||||||
end
|
|
||||||
if ship.body:getX() + ship.img:getWidth() > canvas.width then -- Right game
|
|
||||||
x, y = ship.body:getLinearVelocity()
|
|
||||||
ship.body:setLinearVelocity(-x, y)
|
|
||||||
end
|
|
||||||
if ship.body:getX() < 0 then -- Left game
|
|
||||||
x, y = ship.body:getLinearVelocity()
|
|
||||||
ship.body:setLinearVelocity(-x, y)
|
|
||||||
end
|
|
||||||
if ship.body:getY() + ship.img:getHeight() + moon_margin >= canvas.height then -- Down game
|
|
||||||
ship.body:setLinearVelocity(0, 0)
|
|
||||||
win = true
|
|
||||||
play = false
|
|
||||||
level.num = level.num + 1
|
|
||||||
sounds.complete:play()
|
|
||||||
end
|
|
||||||
|
|
||||||
for key, value in pairs(asteroids) do -- Asteroids
|
|
||||||
local asteroid_temp = {
|
|
||||||
x = asteroids[key].x,
|
|
||||||
y = asteroids[key].y,
|
|
||||||
radius = asteroids_collision
|
|
||||||
}
|
|
||||||
local ship_temp = {
|
|
||||||
x = ship.body:getX() + (ship.img:getWidth() / 2),
|
|
||||||
y = ship.body:getY() + (ship.img:getHeight() / 2),
|
|
||||||
radius = ship.size_collition
|
|
||||||
}
|
|
||||||
if checkCircleCollision(asteroid_temp, ship_temp) then
|
|
||||||
play = false
|
|
||||||
sounds.die:play()
|
|
||||||
sounds.explosion:play()
|
|
||||||
explosion.active = true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
-- DRAW
|
-- DRAW
|
||||||
function love.draw()
|
function love.draw()
|
||||||
-- Camera
|
spaceship.draw()
|
||||||
love.graphics.translate(0, camera.y)
|
|
||||||
-- Background
|
|
||||||
love.graphics.draw(background.img, background.x, background.y, 0, 2, 1)
|
|
||||||
-- Ship
|
|
||||||
if not explosion.active then
|
|
||||||
love.graphics.draw(ship.img, ship.body:getX(), ship.body:getY())
|
|
||||||
if debug then
|
|
||||||
love.graphics.circle('line', ship.body:getX() + (ship.img:getWidth() / 2), ship.body:getY() + (ship.img:getHeight() / 2), ship.size_collition, ship.polygons_collition)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Fire
|
|
||||||
if fire.visible and not explosion.active then
|
|
||||||
love.graphics.draw(fire.img, fire.frames[fire.pos_frame], ship.body:getX(), ship.body:getY() + ship.img:getHeight() + fire.distance_ship)
|
|
||||||
end
|
|
||||||
-- Asteroids
|
|
||||||
for key, value in pairs(asteroids) do
|
|
||||||
love.graphics.draw(value.img, value.x, value.y, value.angle, 1, 1, value.img:getWidth() / 2, value.img:getHeight() / 2)
|
|
||||||
if debug then
|
|
||||||
love.graphics.circle('line', value.x, value.y, asteroids_collision, ship.polygons_collition)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
-- Explosion
|
|
||||||
if explosion.active then
|
|
||||||
love.graphics.draw(explosion.img, explosion.frames[explosion.pos_frame], ship.body:getX(), ship.body:getY() + ship.img:getHeight() / 2)
|
|
||||||
end
|
|
||||||
-- Controls
|
|
||||||
-- Up
|
|
||||||
button_up.y = level.y + (camera.height / 4) + -camera.y
|
|
||||||
local button_frame_up = button.frames[1]
|
|
||||||
if control_up then
|
|
||||||
button_frame_up = button.frames[2]
|
|
||||||
end
|
|
||||||
love.graphics.draw(button.img, button_frame_up, button_up.x, button_up.y)
|
|
||||||
if debug then
|
|
||||||
love.graphics.rectangle('fill', button_up.x, button_up.y, button.img:getWidth(), button.img:getHeight())
|
|
||||||
end
|
|
||||||
-- Right
|
|
||||||
button_right.y = button_up.y + (button.img:getHeight() + (button.img:getHeight() / 3))
|
|
||||||
local button_frame_right = button.frames[1]
|
|
||||||
if control_right then
|
|
||||||
button_frame_right = button.frames[2]
|
|
||||||
end
|
|
||||||
love.graphics.draw(button.img, button_frame_right, button_right.x + (button.img:getWidth() / (2 * button.num_frames)), button_right.y + button.img:getHeight(), 90 * math.pi / 180, 1, 1, button.img:getWidth() / 2, button.img:getHeight() / 2)
|
|
||||||
if debug then
|
|
||||||
love.graphics.rectangle('fill', button_right.x, button_right.y, button.img:getWidth(), button.img:getHeight())
|
|
||||||
end
|
|
||||||
-- Left
|
|
||||||
button_left.y = button_right.y
|
|
||||||
local button_frame_left = button.frames[1]
|
|
||||||
if control_left then
|
|
||||||
button_frame_left = button.frames[2]
|
|
||||||
end
|
|
||||||
love.graphics.draw(button.img, button_frame_left, button_left.x + (button.img:getWidth() / (2 * button.num_frames)), button_left.y, 270 * math.pi / 180, 1, 1, button.img:getWidth() / 2, button.img:getHeight() / 2)
|
|
||||||
if debug then
|
|
||||||
love.graphics.rectangle('fill', button_left.x, button_left.y, button.img:getWidth(), button.img:getHeight())
|
|
||||||
end
|
|
||||||
-- Texts
|
|
||||||
if not play and not win then -- Game over
|
|
||||||
love.graphics.print(text_restart.text, (camera.width / 2) - (text_restart.size / 2), -camera.y + (camera.height / 2))
|
|
||||||
end
|
|
||||||
if not play and win then -- Win
|
|
||||||
love.graphics.print(text_good, (camera.width / 2) - (text_good.size / 2), -camera.y + (camera.height / 2))
|
|
||||||
end
|
|
||||||
love.graphics.print('Level ' .. level.num, level.x, level.y + -camera.y) -- Score
|
|
||||||
end
|
end
|
||||||
|
|
||||||
--------------------------------- Functions
|
-- CONTROLS
|
||||||
-- Get Table length
|
|
||||||
function table_length(T)
|
|
||||||
local count = 0
|
|
||||||
for _ in pairs(T) do count = count + 1 end
|
|
||||||
return count
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Pause system n seconds
|
|
||||||
local clock = os.clock
|
|
||||||
function sleep(n) -- seconds
|
|
||||||
local t0 = clock()
|
|
||||||
while clock() - t0 <= n do end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Collision detection function.
|
|
||||||
function checkCircleCollision(circle1, circle2)
|
|
||||||
local distance = math.sqrt((circle1.x - circle2.x) ^ 2 + (circle1.y - circle2.y) ^ 2)
|
|
||||||
return distance <= circle1.radius + circle2.radius
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Restart level
|
|
||||||
function restart(level_arg)
|
|
||||||
sounds.fire:stop()
|
|
||||||
ship.body = love.physics.newBody(world, (canvas.width / 2) - (ship.img:getWidth() / 2) , ship.img:getHeight(), 'dynamic')
|
|
||||||
num_asteroids = level_arg * 5
|
|
||||||
explosion.pos_frame = 1
|
|
||||||
explosion.active = false
|
|
||||||
-- Generate asteroids
|
|
||||||
asteroids = {}
|
|
||||||
for i=1, num_asteroids do
|
|
||||||
local temp_img = img_asteroide[math.random(1, table_length(img_asteroide))]
|
|
||||||
asteroids[i] = {
|
|
||||||
x = math.random(0, canvas.width - temp_img:getWidth()),
|
|
||||||
y = math.random(window.height / 2, canvas.height - temp_img:getHeight()),
|
|
||||||
speed = math.random(1, max_speed_asteroids),
|
|
||||||
img = temp_img,
|
|
||||||
angle = math.random(0, 90)
|
|
||||||
}
|
|
||||||
end
|
|
||||||
-- Set ship position
|
|
||||||
win = false
|
|
||||||
play = true
|
|
||||||
start_time = 0
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Controls
|
|
||||||
function love.keyreleased(key)
|
function love.keyreleased(key)
|
||||||
sounds.fire:stop()
|
-- sounds.keyreleased(key)
|
||||||
end
|
end
|
||||||
|
|
||||||
function love.mousereleased(key)
|
function love.mousereleased(key)
|
||||||
sounds.fire:stop()
|
-- sounds.mousereleased(key)
|
||||||
end,
|
end
|
397
main_old.lua
Normal file
397
main_old.lua
Normal file
@ -0,0 +1,397 @@
|
|||||||
|
local start_time = 0
|
||||||
|
-- LOAD
|
||||||
|
function love.load()
|
||||||
|
-- Configuration
|
||||||
|
math.randomseed(os.time())
|
||||||
|
width, height = love.window.getDesktopDimensions( display )
|
||||||
|
window = { width = width , height = height }
|
||||||
|
fullscreen = false
|
||||||
|
love.window.setMode(window.width, window.height, {resizable=true})
|
||||||
|
font_main = love.graphics.newFont('assets/fonts/main.ttf', 80) -- Font
|
||||||
|
love.graphics.setFont(font_main)
|
||||||
|
text_restart = { text = 'You die' }
|
||||||
|
text_restart.size = font_main:getWidth(text_restart.text)
|
||||||
|
text_good = { text = 'Good' }
|
||||||
|
text_good.size = font_main:getWidth(text_good.text)
|
||||||
|
camera = { x = 0, y = 0, width = window.width, height = window.height }
|
||||||
|
debug = false
|
||||||
|
play = true
|
||||||
|
win = false
|
||||||
|
level = { num = 1, x = 50, y = 50, max = 20 }
|
||||||
|
love.window.setFullscreen(fullscreen, 'exclusive')
|
||||||
|
love.window.setTitle('Alunizaje')
|
||||||
|
background = { x = 0, y = 0, img = love.graphics.newImage('assets/sprites/background/background.png') }
|
||||||
|
canvas = { width = width, height = 2880 }
|
||||||
|
moon_margin = 100
|
||||||
|
-- Physics
|
||||||
|
world_meter = 64
|
||||||
|
gravity = 2
|
||||||
|
love.physics.setMeter(world_meter) -- Height earth in meters
|
||||||
|
world = love.physics.newWorld(0, gravity * world_meter, true) -- Make earth
|
||||||
|
-- Ship
|
||||||
|
ship = { x = canvas.width / 2, y = 0 , power = 1000 , size_collition = 28, polygons_collition = 8 }
|
||||||
|
ship.img = love.graphics.newImage('assets/sprites/spaceship/body.png')
|
||||||
|
ship.body = love.physics.newBody(world, (canvas.width / 2) - (ship.img:getWidth() / 2) , ship.y, 'dynamic')
|
||||||
|
ship.shape = love.physics.newCircleShape(20)
|
||||||
|
ship.fixture = love.physics.newFixture(ship.body, ship.shape, 1)
|
||||||
|
ship.fixture:setRestitution(0.9)
|
||||||
|
ship.time_start = 1
|
||||||
|
start_time = 0
|
||||||
|
-- Fire
|
||||||
|
fire = {}
|
||||||
|
fire.img = love.graphics.newImage('assets/sprites/spaceship/fire.png')
|
||||||
|
fire.num_frames = 4
|
||||||
|
fire.pos_frame = 0
|
||||||
|
fire.visible = false
|
||||||
|
fire.distance_ship = 10
|
||||||
|
fire.frame_width = fire.img:getWidth() / fire.num_frames
|
||||||
|
fire.frames = {
|
||||||
|
love.graphics.newQuad(fire.frame_width * 0, 0, fire.frame_width, fire.frame_width, fire.img:getWidth(), fire.img:getHeight()),
|
||||||
|
love.graphics.newQuad(fire.frame_width * 1, 0, fire.frame_width, fire.frame_width, fire.img:getWidth(), fire.img:getHeight()),
|
||||||
|
love.graphics.newQuad(fire.frame_width * 2, 0, fire.frame_width, fire.frame_width, fire.img:getWidth(), fire.img:getHeight()),
|
||||||
|
love.graphics.newQuad(fire.frame_width * 3, 0, fire.frame_width, fire.frame_width, fire.img:getWidth(), fire.img:getHeight())
|
||||||
|
}
|
||||||
|
-- Explosion
|
||||||
|
explosion = {}
|
||||||
|
explosion.img = love.graphics.newImage('assets/sprites/spaceship/explosion.png')
|
||||||
|
explosion.num_frames = 11
|
||||||
|
explosion.pos_frame = 1
|
||||||
|
explosion.active = false
|
||||||
|
explosion.finish = false
|
||||||
|
explosion.time = 0
|
||||||
|
explosion.speed = 0.05
|
||||||
|
explosion.frame_width = explosion.img:getWidth() / explosion.num_frames
|
||||||
|
explosion.frame_height = explosion.img:getHeight()
|
||||||
|
explosion.frames = {
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 0, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 1, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 2, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 3, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 4, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 5, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 6, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 7, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 8, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 9, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight()),
|
||||||
|
love.graphics.newQuad(explosion.frame_width * 10, 0, explosion.frame_width, explosion.frame_height, explosion.img:getWidth(), explosion.img:getHeight())
|
||||||
|
}
|
||||||
|
|
||||||
|
-- Button
|
||||||
|
control_up, control_right, control_left, control_quit = false, false, false, false
|
||||||
|
button = {}
|
||||||
|
button.img = love.graphics.newImage('assets/sprites/hui/button.png')
|
||||||
|
button.num_frames = 2
|
||||||
|
button.frame_width = button.img:getWidth() / button.num_frames
|
||||||
|
button.frame_height = button.img:getHeight()
|
||||||
|
button.frames = {
|
||||||
|
love.graphics.newQuad(button.frame_width * 0, 0, button.frame_width, button.frame_height, button.img:getWidth(), button.img:getHeight()),
|
||||||
|
love.graphics.newQuad(button.frame_width * 1, 0, button.frame_width, button.frame_height, button.img:getWidth(), button.img:getHeight())
|
||||||
|
}
|
||||||
|
button_up = {}
|
||||||
|
button_up.x = window.width - (button.img:getWidth() / button.num_frames) - (button.img:getWidth() / (2 * button.num_frames))
|
||||||
|
button_up.y = level.y + (camera.height / 4) + -camera.y
|
||||||
|
button_right = {}
|
||||||
|
button_right.x = button_up.x
|
||||||
|
button_right.y = button_up.y + (button.img:getHeight() / 3)
|
||||||
|
button_left = {}
|
||||||
|
button_left.x = button.img:getWidth() / (2 * button.num_frames)
|
||||||
|
button_left.y = button_right.y
|
||||||
|
-- Generates initial asteroids
|
||||||
|
asteroids_collision = 40
|
||||||
|
asteroids_collision_polygon = 8
|
||||||
|
max_speed_asteroids = 5
|
||||||
|
img_asteroide = {
|
||||||
|
love.graphics.newImage('assets/sprites/asteroids/1.png'),
|
||||||
|
love.graphics.newImage('assets/sprites/asteroids/2.png'),
|
||||||
|
love.graphics.newImage('assets/sprites/asteroids/3.png')
|
||||||
|
}
|
||||||
|
-- Audios
|
||||||
|
sounds = {}
|
||||||
|
sounds.die = love.audio.newSource('assets/audios/sound/die.wav', 'static')
|
||||||
|
sounds.explosion = love.audio.newSource('assets/audios/sound/explosion_bit.wav', 'static')
|
||||||
|
sounds.ambient_1 = love.audio.newSource('assets/audios/sound/ambient_1.wav')
|
||||||
|
sounds.complete = love.audio.newSource('assets/audios/sound/complete.wav')
|
||||||
|
sounds.fire = love.audio.newSource('assets/audios/sound/fire.wav', 'static')
|
||||||
|
sounds.ambient_1:setLooping(true)
|
||||||
|
sounds.ambient_1:play()
|
||||||
|
|
||||||
|
restart(level.num)
|
||||||
|
end
|
||||||
|
|
||||||
|
-- UPDATE
|
||||||
|
function love.update(dt)
|
||||||
|
-- Fix position ship
|
||||||
|
if ship.y < 0 then
|
||||||
|
ship.y = 0
|
||||||
|
end
|
||||||
|
-- Count time
|
||||||
|
start_time = dt + start_time
|
||||||
|
-- Sprite
|
||||||
|
if not explosion.finish and explosion.active then -- Explosion
|
||||||
|
explosion.time = explosion.time + dt
|
||||||
|
if explosion.time > explosion.speed then
|
||||||
|
explosion.pos_frame = explosion.pos_frame + 1
|
||||||
|
explosion.time = 0
|
||||||
|
end
|
||||||
|
if explosion.pos_frame > explosion.num_frames then
|
||||||
|
sleep(1)
|
||||||
|
restart(level.num)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Restart
|
||||||
|
if not explosion.active and not play then
|
||||||
|
sleep(3)
|
||||||
|
restart(level.num)
|
||||||
|
end
|
||||||
|
if play then
|
||||||
|
-- Phytics world
|
||||||
|
world:update(dt)
|
||||||
|
-- Sprite
|
||||||
|
fire.visible = false
|
||||||
|
if fire.pos_frame < fire.num_frames then -- Fire
|
||||||
|
fire.pos_frame = fire.pos_frame + 1
|
||||||
|
else
|
||||||
|
fire.pos_frame = 1
|
||||||
|
end
|
||||||
|
-- Controls
|
||||||
|
control_up, control_right, control_left, control_quit = false, false, false, false
|
||||||
|
-- Keyboard
|
||||||
|
if love.keyboard.isDown('escape') or love.keyboard.isDown('q') then
|
||||||
|
control_quit = true
|
||||||
|
end
|
||||||
|
if love.keyboard.isDown('right') then
|
||||||
|
control_right = true
|
||||||
|
elseif love.keyboard.isDown('left') then
|
||||||
|
control_left = true
|
||||||
|
end
|
||||||
|
if love.keyboard.isDown('up') then
|
||||||
|
control_up = true
|
||||||
|
end
|
||||||
|
-- Mouse
|
||||||
|
if love.mouse.isDown(1) then
|
||||||
|
local x, y = love.mouse.getPosition()
|
||||||
|
-- Up
|
||||||
|
if x > button_up.x and x < button_up.x + button.img:getWidth() and y > button_up.y + camera.y and y < button_up.y + button.img:getHeight() + camera.y then
|
||||||
|
control_up = true
|
||||||
|
end
|
||||||
|
-- Right
|
||||||
|
if x > button_right.x and x < button_right.x + button.img:getWidth() and y > button_right.y + camera.y and y < button_right.y + button.img:getHeight() + camera.y then
|
||||||
|
control_right = true
|
||||||
|
elseif x > button_left.x and x < button_left.x + button.img:getWidth() and y > button_left.y + camera.y and y < button_left.y + button.img:getHeight() + camera.y then
|
||||||
|
control_left = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Ship move
|
||||||
|
if control_up then
|
||||||
|
ship.body:applyForce(0, -ship.power)
|
||||||
|
fire.visible = true
|
||||||
|
sounds.fire:play()
|
||||||
|
end
|
||||||
|
if control_right then
|
||||||
|
ship.body:applyForce(ship.power, 0)
|
||||||
|
fire.visible = true
|
||||||
|
sounds.fire:play()
|
||||||
|
elseif control_left then
|
||||||
|
ship.body:applyForce(-ship.power, 0)
|
||||||
|
fire.visible = true
|
||||||
|
sounds.fire:play()
|
||||||
|
end
|
||||||
|
if control_quit then
|
||||||
|
love.event.push('quit')
|
||||||
|
end
|
||||||
|
-- Rotate asteroids
|
||||||
|
for key, value in pairs(asteroids) do
|
||||||
|
value.angle = asteroids[key].angle + (dt * math.pi / 10)
|
||||||
|
value.x = asteroids[key].x - asteroids[key].speed
|
||||||
|
end
|
||||||
|
-- Destroy asteroids
|
||||||
|
for key, value in pairs(asteroids) do
|
||||||
|
if value.x + asteroids[key].img:getWidth() < 0 then
|
||||||
|
table.remove(asteroids, key)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Create asteroids
|
||||||
|
if table_length(asteroids) < num_asteroids then
|
||||||
|
local temp_img = img_asteroide[math.random(1, table_length(img_asteroide))]
|
||||||
|
asteroids[table_length(asteroids) + 1] = {
|
||||||
|
x = canvas.width + temp_img:getWidth(),
|
||||||
|
y = math.random(window.height, canvas.height - temp_img:getHeight()),
|
||||||
|
speed = math.random(1, max_speed_asteroids),
|
||||||
|
img = temp_img,
|
||||||
|
angle = math.random(0, 90)}
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Camera
|
||||||
|
camera.y = 0
|
||||||
|
if camera.height / 3 <= ship.body:getY() then -- Top
|
||||||
|
camera.y = -ship.body:getY() + (camera.height / 3)
|
||||||
|
end
|
||||||
|
if canvas.height - ((camera.height / 3) * 2) < ship.body:getY() then -- Down
|
||||||
|
camera.y = -canvas.height + camera.height
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Collision
|
||||||
|
if ship.body:getY() <= 0 then -- Top game
|
||||||
|
x, y = ship.body:getLinearVelocity()
|
||||||
|
ship.body:setLinearVelocity(x, -y)
|
||||||
|
end
|
||||||
|
if ship.body:getX() + ship.img:getWidth() > canvas.width then -- Right game
|
||||||
|
x, y = ship.body:getLinearVelocity()
|
||||||
|
ship.body:setLinearVelocity(-x, y)
|
||||||
|
end
|
||||||
|
if ship.body:getX() < 0 then -- Left game
|
||||||
|
x, y = ship.body:getLinearVelocity()
|
||||||
|
ship.body:setLinearVelocity(-x, y)
|
||||||
|
end
|
||||||
|
if ship.body:getY() + ship.img:getHeight() + moon_margin >= canvas.height then -- Down game
|
||||||
|
ship.body:setLinearVelocity(0, 0)
|
||||||
|
win = true
|
||||||
|
play = false
|
||||||
|
level.num = level.num + 1
|
||||||
|
sounds.complete:play()
|
||||||
|
end
|
||||||
|
|
||||||
|
for key, value in pairs(asteroids) do -- Asteroids
|
||||||
|
local asteroid_temp = {
|
||||||
|
x = asteroids[key].x,
|
||||||
|
y = asteroids[key].y,
|
||||||
|
radius = asteroids_collision
|
||||||
|
}
|
||||||
|
local ship_temp = {
|
||||||
|
x = ship.body:getX() + (ship.img:getWidth() / 2),
|
||||||
|
y = ship.body:getY() + (ship.img:getHeight() / 2),
|
||||||
|
radius = ship.size_collition
|
||||||
|
}
|
||||||
|
if checkCircleCollision(asteroid_temp, ship_temp) then
|
||||||
|
play = false
|
||||||
|
sounds.die:play()
|
||||||
|
sounds.explosion:play()
|
||||||
|
explosion.active = true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- DRAW
|
||||||
|
function love.draw()
|
||||||
|
-- Camera
|
||||||
|
love.graphics.translate(0, camera.y)
|
||||||
|
-- Background
|
||||||
|
love.graphics.draw(background.img, background.x, background.y, 0, 2, 1)
|
||||||
|
-- Ship
|
||||||
|
if not explosion.active then
|
||||||
|
love.graphics.draw(ship.img, ship.body:getX(), ship.body:getY())
|
||||||
|
if debug then
|
||||||
|
love.graphics.circle('line', ship.body:getX() + (ship.img:getWidth() / 2), ship.body:getY() + (ship.img:getHeight() / 2), ship.size_collition, ship.polygons_collition)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Fire
|
||||||
|
if fire.visible and not explosion.active then
|
||||||
|
love.graphics.draw(fire.img, fire.frames[fire.pos_frame], ship.body:getX(), ship.body:getY() + ship.img:getHeight() + fire.distance_ship)
|
||||||
|
end
|
||||||
|
-- Asteroids
|
||||||
|
for key, value in pairs(asteroids) do
|
||||||
|
love.graphics.draw(value.img, value.x, value.y, value.angle, 1, 1, value.img:getWidth() / 2, value.img:getHeight() / 2)
|
||||||
|
if debug then
|
||||||
|
love.graphics.circle('line', value.x, value.y, asteroids_collision, ship.polygons_collition)
|
||||||
|
end
|
||||||
|
end
|
||||||
|
-- Explosion
|
||||||
|
if explosion.active then
|
||||||
|
love.graphics.draw(explosion.img, explosion.frames[explosion.pos_frame], ship.body:getX(), ship.body:getY() + ship.img:getHeight() / 2)
|
||||||
|
end
|
||||||
|
-- Controls
|
||||||
|
-- Up
|
||||||
|
button_up.y = level.y + (camera.height / 4) + -camera.y
|
||||||
|
local button_frame_up = button.frames[1]
|
||||||
|
if control_up then
|
||||||
|
button_frame_up = button.frames[2]
|
||||||
|
end
|
||||||
|
love.graphics.draw(button.img, button_frame_up, button_up.x, button_up.y)
|
||||||
|
if debug then
|
||||||
|
love.graphics.rectangle('fill', button_up.x, button_up.y, button.img:getWidth(), button.img:getHeight())
|
||||||
|
end
|
||||||
|
-- Right
|
||||||
|
button_right.y = button_up.y + (button.img:getHeight() + (button.img:getHeight() / 3))
|
||||||
|
local button_frame_right = button.frames[1]
|
||||||
|
if control_right then
|
||||||
|
button_frame_right = button.frames[2]
|
||||||
|
end
|
||||||
|
love.graphics.draw(button.img, button_frame_right, button_right.x + (button.img:getWidth() / (2 * button.num_frames)), button_right.y + button.img:getHeight(), 90 * math.pi / 180, 1, 1, button.img:getWidth() / 2, button.img:getHeight() / 2)
|
||||||
|
if debug then
|
||||||
|
love.graphics.rectangle('fill', button_right.x, button_right.y, button.img:getWidth(), button.img:getHeight())
|
||||||
|
end
|
||||||
|
-- Left
|
||||||
|
button_left.y = button_right.y
|
||||||
|
local button_frame_left = button.frames[1]
|
||||||
|
if control_left then
|
||||||
|
button_frame_left = button.frames[2]
|
||||||
|
end
|
||||||
|
love.graphics.draw(button.img, button_frame_left, button_left.x + (button.img:getWidth() / (2 * button.num_frames)), button_left.y, 270 * math.pi / 180, 1, 1, button.img:getWidth() / 2, button.img:getHeight() / 2)
|
||||||
|
if debug then
|
||||||
|
love.graphics.rectangle('fill', button_left.x, button_left.y, button.img:getWidth(), button.img:getHeight())
|
||||||
|
end
|
||||||
|
-- Texts
|
||||||
|
if not play and not win then -- Game over
|
||||||
|
love.graphics.print(text_restart.text, (camera.width / 2) - (text_restart.size / 2), -camera.y + (camera.height / 2))
|
||||||
|
end
|
||||||
|
if not play and win then -- Win
|
||||||
|
love.graphics.print(text_good, (camera.width / 2) - (text_good.size / 2), -camera.y + (camera.height / 2))
|
||||||
|
end
|
||||||
|
love.graphics.print('Level ' .. level.num, level.x, level.y + -camera.y) -- Score
|
||||||
|
end
|
||||||
|
|
||||||
|
--------------------------------- Functions
|
||||||
|
-- Get Table length
|
||||||
|
function table_length(T)
|
||||||
|
local count = 0
|
||||||
|
for _ in pairs(T) do count = count + 1 end
|
||||||
|
return count
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Pause system n seconds
|
||||||
|
local clock = os.clock
|
||||||
|
function sleep(n) -- seconds
|
||||||
|
local t0 = clock()
|
||||||
|
while clock() - t0 <= n do end
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Collision detection function.
|
||||||
|
function checkCircleCollision(circle1, circle2)
|
||||||
|
local distance = math.sqrt((circle1.x - circle2.x) ^ 2 + (circle1.y - circle2.y) ^ 2)
|
||||||
|
return distance <= circle1.radius + circle2.radius
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Restart level
|
||||||
|
function restart(level_arg)
|
||||||
|
sounds.fire:stop()
|
||||||
|
ship.body = love.physics.newBody(world, (canvas.width / 2) - (ship.img:getWidth() / 2) , ship.img:getHeight(), 'dynamic')
|
||||||
|
num_asteroids = level_arg * 5
|
||||||
|
explosion.pos_frame = 1
|
||||||
|
explosion.active = false
|
||||||
|
-- Generate asteroids
|
||||||
|
asteroids = {}
|
||||||
|
for i=1, num_asteroids do
|
||||||
|
local temp_img = img_asteroide[math.random(1, table_length(img_asteroide))]
|
||||||
|
asteroids[i] = {
|
||||||
|
x = math.random(0, canvas.width - temp_img:getWidth()),
|
||||||
|
y = math.random(window.height / 2, canvas.height - temp_img:getHeight()),
|
||||||
|
speed = math.random(1, max_speed_asteroids),
|
||||||
|
img = temp_img,
|
||||||
|
angle = math.random(0, 90)
|
||||||
|
}
|
||||||
|
end
|
||||||
|
-- Set ship position
|
||||||
|
win = false
|
||||||
|
play = true
|
||||||
|
start_time = 0
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Controls
|
||||||
|
function love.keyreleased(key)
|
||||||
|
sounds.fire:stop()
|
||||||
|
end
|
||||||
|
|
||||||
|
function love.mousereleased(key)
|
||||||
|
sounds.fire:stop()
|
||||||
|
end
|
Loading…
Reference in New Issue
Block a user