consolidate all repos to one for archive
114
semester_5/uvod_v_razvoj_racunalniskih_iger/game_1/.gitignore
vendored
Normal file
@@ -0,0 +1,114 @@
|
||||
## Java
|
||||
|
||||
*.class
|
||||
*.war
|
||||
*.ear
|
||||
hs_err_pid*
|
||||
|
||||
## Robovm
|
||||
/ios/robovm-build/
|
||||
|
||||
## GWT
|
||||
/html/war/
|
||||
/html/gwt-unitCache/
|
||||
.apt_generated/
|
||||
.gwt/
|
||||
gwt-unitCache/
|
||||
www-test/
|
||||
.gwt-tmp/
|
||||
|
||||
## Android Studio and Intellij and Android in general
|
||||
/android/libs/armeabi-v7a/
|
||||
/android/libs/arm64-v8a/
|
||||
/android/libs/x86/
|
||||
/android/libs/x86_64/
|
||||
/android/gen/
|
||||
.idea/
|
||||
*.ipr
|
||||
*.iws
|
||||
*.iml
|
||||
/android/out/
|
||||
com_crashlytics_export_strings.xml
|
||||
|
||||
## Eclipse
|
||||
|
||||
.classpath
|
||||
.project
|
||||
.metadata/
|
||||
/android/bin/
|
||||
/core/bin/
|
||||
/desktop/bin/
|
||||
/html/bin/
|
||||
/ios/bin/
|
||||
*.tmp
|
||||
*.bak
|
||||
*.swp
|
||||
*~.nib
|
||||
.settings/
|
||||
.loadpath
|
||||
.externalToolBuilders/
|
||||
*.launch
|
||||
|
||||
## NetBeans
|
||||
|
||||
/nbproject/private/
|
||||
/android/nbproject/private/
|
||||
/core/nbproject/private/
|
||||
/desktop/nbproject/private/
|
||||
/html/nbproject/private/
|
||||
/ios/nbproject/private/
|
||||
|
||||
/build/
|
||||
/android/build/
|
||||
/core/build/
|
||||
/desktop/build/
|
||||
/html/build/
|
||||
/ios/build/
|
||||
|
||||
/nbbuild/
|
||||
/android/nbbuild/
|
||||
/core/nbbuild/
|
||||
/desktop/nbbuild/
|
||||
/html/nbbuild/
|
||||
/ios/nbbuild/
|
||||
|
||||
/dist/
|
||||
/android/dist/
|
||||
/core/dist/
|
||||
/desktop/dist/
|
||||
/html/dist/
|
||||
/ios/dist/
|
||||
|
||||
/nbdist/
|
||||
/android/nbdist/
|
||||
/core/nbdist/
|
||||
/desktop/nbdist/
|
||||
/html/nbdist/
|
||||
/ios/nbdist/
|
||||
|
||||
nbactions.xml
|
||||
nb-configuration.xml
|
||||
|
||||
## Gradle
|
||||
|
||||
/local.properties
|
||||
.gradle/
|
||||
gradle-app.setting
|
||||
/build/
|
||||
/android/build/
|
||||
/core/build/
|
||||
/desktop/build/
|
||||
/html/build/
|
||||
/ios/build/
|
||||
|
||||
## OS Specific
|
||||
.DS_Store
|
||||
Thumbs.db
|
||||
|
||||
## iOS
|
||||
/ios/xcode/*.xcodeproj/*
|
||||
!/ios/xcode/*.xcodeproj/xcshareddata
|
||||
!/ios/xcode/*.xcodeproj/project.pbxproj
|
||||
/ios/xcode/native/
|
||||
/ios/IOSLauncher.app
|
||||
/ios/IOSLauncher.app.dSYM
|
@@ -0,0 +1,3 @@
|
||||
To je igra kjer poskušamo preživeti najdle časa.
|
||||
S tem da pobiramo metke in strelamo na slabe ljudi.
|
||||
Da dobimo čim večje stevilo točk.
|
@@ -0,0 +1,141 @@
|
||||
Untitled
|
||||
- Delay -
|
||||
active: false
|
||||
- Duration -
|
||||
lowMin: 100.0
|
||||
lowMax: 100.0
|
||||
- Count -
|
||||
min: 0
|
||||
max: 200
|
||||
- Emission -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 200.0
|
||||
highMax: 200.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Life -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 400.0
|
||||
highMax: 800.0
|
||||
relative: false
|
||||
scalingCount: 3
|
||||
scaling0: 1.0
|
||||
scaling1: 0.0
|
||||
scaling2: 0.0
|
||||
timelineCount: 3
|
||||
timeline0: 0.0
|
||||
timeline1: 0.60273975
|
||||
timeline2: 0.9931507
|
||||
independent: false
|
||||
- Life Offset -
|
||||
active: false
|
||||
independent: false
|
||||
- X Offset -
|
||||
active: false
|
||||
- Y Offset -
|
||||
active: false
|
||||
- Spawn Shape -
|
||||
shape: point
|
||||
- Spawn Width -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 0.0
|
||||
highMax: 0.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Spawn Height -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 0.0
|
||||
highMax: 0.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- X Scale -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 6.0
|
||||
highMax: 6.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Y Scale -
|
||||
active: false
|
||||
- Velocity -
|
||||
active: true
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 3.0
|
||||
highMax: 30.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Angle -
|
||||
active: true
|
||||
lowMin: 270.0
|
||||
lowMax: 270.0
|
||||
highMin: 225.0
|
||||
highMax: 315.0
|
||||
relative: false
|
||||
scalingCount: 3
|
||||
scaling0: 1.0
|
||||
scaling1: 0.0
|
||||
scaling2: 0.0
|
||||
timelineCount: 3
|
||||
timeline0: 0.0
|
||||
timeline1: 0.1780822
|
||||
timeline2: 1.0
|
||||
- Rotation -
|
||||
active: false
|
||||
- Wind -
|
||||
active: false
|
||||
- Gravity -
|
||||
active: false
|
||||
- Tint -
|
||||
colorsCount: 3
|
||||
colors0: 0.8862745
|
||||
colors1: 0.0
|
||||
colors2: 0.8392157
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Transparency -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 1.0
|
||||
highMax: 1.0
|
||||
relative: false
|
||||
scalingCount: 4
|
||||
scaling0: 0.0
|
||||
scaling1: 1.0
|
||||
scaling2: 0.75
|
||||
scaling3: 0.0
|
||||
timelineCount: 4
|
||||
timeline0: 0.0
|
||||
timeline1: 0.2
|
||||
timeline2: 0.8
|
||||
timeline3: 1.0
|
||||
- Options -
|
||||
attached: false
|
||||
continuous: false
|
||||
aligned: false
|
||||
additive: false
|
||||
behind: false
|
||||
premultipliedAlpha: false
|
||||
spriteMode: single
|
||||
- Image Paths -
|
||||
particle.png
|
||||
|
@@ -0,0 +1,141 @@
|
||||
Untitled
|
||||
- Delay -
|
||||
active: false
|
||||
- Duration -
|
||||
lowMin: 100.0
|
||||
lowMax: 100.0
|
||||
- Count -
|
||||
min: 0
|
||||
max: 50
|
||||
- Emission -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 500.0
|
||||
highMax: 500.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Life -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 400.0
|
||||
highMax: 800.0
|
||||
relative: false
|
||||
scalingCount: 3
|
||||
scaling0: 1.0
|
||||
scaling1: 1.0
|
||||
scaling2: 0.3
|
||||
timelineCount: 3
|
||||
timeline0: 0.0
|
||||
timeline1: 0.66
|
||||
timeline2: 1.0
|
||||
independent: false
|
||||
- Life Offset -
|
||||
active: false
|
||||
independent: false
|
||||
- X Offset -
|
||||
active: false
|
||||
- Y Offset -
|
||||
active: false
|
||||
- Spawn Shape -
|
||||
shape: point
|
||||
- Spawn Width -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 0.0
|
||||
highMax: 0.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Spawn Height -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 0.0
|
||||
highMax: 0.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- X Scale -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 6.0
|
||||
highMax: 6.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Y Scale -
|
||||
active: false
|
||||
- Velocity -
|
||||
active: true
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 3.0
|
||||
highMax: 30.0
|
||||
relative: false
|
||||
scalingCount: 1
|
||||
scaling0: 1.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Angle -
|
||||
active: true
|
||||
lowMin: 90.0
|
||||
lowMax: 90.0
|
||||
highMin: 45.0
|
||||
highMax: 135.0
|
||||
relative: false
|
||||
scalingCount: 3
|
||||
scaling0: 1.0
|
||||
scaling1: 0.0
|
||||
scaling2: 0.0
|
||||
timelineCount: 3
|
||||
timeline0: 0.0
|
||||
timeline1: 0.48630136
|
||||
timeline2: 1.0
|
||||
- Rotation -
|
||||
active: false
|
||||
- Wind -
|
||||
active: false
|
||||
- Gravity -
|
||||
active: false
|
||||
- Tint -
|
||||
colorsCount: 3
|
||||
colors0: 0.8862745
|
||||
colors1: 0.07058824
|
||||
colors2: 0.0
|
||||
timelineCount: 1
|
||||
timeline0: 0.0
|
||||
- Transparency -
|
||||
lowMin: 0.0
|
||||
lowMax: 0.0
|
||||
highMin: 1.0
|
||||
highMax: 1.0
|
||||
relative: false
|
||||
scalingCount: 4
|
||||
scaling0: 0.0
|
||||
scaling1: 1.0
|
||||
scaling2: 0.75
|
||||
scaling3: 0.0
|
||||
timelineCount: 4
|
||||
timeline0: 0.0
|
||||
timeline1: 0.2
|
||||
timeline2: 0.8
|
||||
timeline3: 1.0
|
||||
- Options -
|
||||
attached: false
|
||||
continuous: false
|
||||
aligned: false
|
||||
additive: true
|
||||
behind: false
|
||||
premultipliedAlpha: false
|
||||
spriteMode: single
|
||||
- Image Paths -
|
||||
particle.png
|
||||
|
After Width: | Height: | Size: 1.8 KiB |
@@ -0,0 +1,62 @@
|
||||
|
||||
texture.png
|
||||
size: 2048, 2048
|
||||
format: RGBA8888
|
||||
filter: Nearest, Nearest
|
||||
repeat: none
|
||||
background
|
||||
rotate: false
|
||||
xy: 2, 175
|
||||
size: 1024, 1024
|
||||
orig: 1024, 1024
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
ball
|
||||
rotate: false
|
||||
xy: 2, 73
|
||||
size: 100, 100
|
||||
orig: 100, 100
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
bullet
|
||||
rotate: false
|
||||
xy: 2, 2
|
||||
size: 16, 16
|
||||
orig: 16, 16
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
robot
|
||||
rotate: false
|
||||
xy: 104, 124
|
||||
size: 43, 49
|
||||
orig: 43, 49
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
soldier
|
||||
rotate: false
|
||||
xy: 1028, 1147
|
||||
size: 43, 52
|
||||
orig: 43, 52
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
survivor
|
||||
rotate: false
|
||||
xy: 2, 20
|
||||
size: 43, 51
|
||||
orig: 43, 51
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
u_bullet
|
||||
rotate: false
|
||||
xy: 1073, 1159
|
||||
size: 40, 40
|
||||
orig: 40, 40
|
||||
offset: 0, 0
|
||||
index: -1
|
||||
zombie
|
||||
rotate: false
|
||||
xy: 1028, 1096
|
||||
size: 43, 49
|
||||
orig: 43, 49
|
||||
offset: 0, 0
|
||||
index: -1
|
After Width: | Height: | Size: 1.9 MiB |
After Width: | Height: | Size: 1.6 MiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 578 B |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.1 KiB |
After Width: | Height: | Size: 2.2 KiB |
After Width: | Height: | Size: 1.4 KiB |
After Width: | Height: | Size: 2.1 KiB |
@@ -0,0 +1,65 @@
|
||||
buildscript {
|
||||
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
gradlePluginPortal()
|
||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
google()
|
||||
}
|
||||
dependencies {
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
allprojects {
|
||||
apply plugin: "eclipse"
|
||||
|
||||
version = '1.0'
|
||||
ext {
|
||||
appName = "My GDX Game"
|
||||
gdxVersion = '1.12.0'
|
||||
roboVMVersion = '2.3.20'
|
||||
box2DLightsVersion = '1.5'
|
||||
ashleyVersion = '1.7.4'
|
||||
aiVersion = '1.8.2'
|
||||
gdxControllersVersion = '2.2.1'
|
||||
}
|
||||
|
||||
repositories {
|
||||
mavenLocal()
|
||||
mavenCentral()
|
||||
google()
|
||||
gradlePluginPortal()
|
||||
maven { url "https://oss.sonatype.org/content/repositories/snapshots/" }
|
||||
maven { url "https://oss.sonatype.org/content/repositories/releases/" }
|
||||
maven { url "https://jitpack.io" }
|
||||
}
|
||||
}
|
||||
|
||||
project(":desktop") {
|
||||
apply plugin: "java-library"
|
||||
|
||||
|
||||
dependencies {
|
||||
implementation project(":core")
|
||||
api "com.badlogicgames.gdx:gdx-backend-lwjgl3:$gdxVersion"
|
||||
api "com.badlogicgames.gdx:gdx-platform:$gdxVersion:natives-desktop"
|
||||
api "com.badlogicgames.gdx:gdx-freetype-platform:$gdxVersion:natives-desktop"
|
||||
api "com.badlogicgames.gdx:gdx-tools:$gdxVersion"
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
project(":core") {
|
||||
apply plugin: "java-library"
|
||||
|
||||
|
||||
dependencies {
|
||||
api "com.badlogicgames.gdx:gdx:$gdxVersion"
|
||||
api "com.badlogicgames.gdx:gdx-freetype:$gdxVersion"
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,6 @@
|
||||
sourceCompatibility = 1.7
|
||||
[compileJava, compileTestJava]*.options*.encoding = 'UTF-8'
|
||||
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
|
||||
eclipse.project.name = appName + "-core"
|
@@ -0,0 +1,12 @@
|
||||
package com.mygdx.BouncingBalls;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
|
||||
public class Ball {
|
||||
public int x = 0;
|
||||
public int y = 0;
|
||||
public int radius = 20;
|
||||
public Color color;
|
||||
|
||||
public float speed = 0;
|
||||
}
|
@@ -0,0 +1,75 @@
|
||||
package com.mygdx.BouncingBalls;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
public class Game extends ApplicationAdapter {
|
||||
private ShapeRenderer shapeRenderer;
|
||||
|
||||
private final Array<Ball> entities;
|
||||
|
||||
int gravity = 100;
|
||||
|
||||
public Game() {
|
||||
entities = new Array<>();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
shapeRenderer = new ShapeRenderer();
|
||||
}
|
||||
|
||||
public void update(){
|
||||
if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
|
||||
Ball ball = new Ball();
|
||||
ball.x = Gdx.input.getX();
|
||||
ball.y = Gdx.graphics.getHeight() - Gdx.input.getY();
|
||||
ball.radius = MathUtils.random(20,75);
|
||||
ball.color = new Color(
|
||||
MathUtils.random(), // Random red component
|
||||
MathUtils.random(), // Random green component
|
||||
MathUtils.random(), // Random blue component
|
||||
1 // Alpha (opacity) set to 1 for full opacity
|
||||
);
|
||||
entities.add(ball);
|
||||
}
|
||||
|
||||
for (Ball ball : entities) {
|
||||
ball.speed *= 0.9999;
|
||||
ball.speed += gravity * Gdx.graphics.getDeltaTime();
|
||||
ball.y -= ball.speed;
|
||||
if (ball.y - ball.radius < 0) {
|
||||
ball.y = ball.radius;
|
||||
ball.speed = -ball.speed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
for (Ball ball : entities) {
|
||||
shapeRenderer.setColor(ball.color);
|
||||
shapeRenderer.circle(ball.x, ball.y, ball.radius);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
Gdx.gl.glClearColor(0, 0, 0, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
update();
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Filled);
|
||||
draw();
|
||||
shapeRenderer.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
shapeRenderer.dispose();
|
||||
}
|
||||
}
|
@@ -0,0 +1,57 @@
|
||||
package com.mygdx.RotatingBall;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.Sprite;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
|
||||
public class Game extends ApplicationAdapter {
|
||||
private SpriteBatch batch;
|
||||
private Texture background;
|
||||
private Sprite ball;
|
||||
private Texture ballT;
|
||||
float pi = 3.14159265359f;
|
||||
float posX = 0;
|
||||
float speed = 200;
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
batch = new SpriteBatch();
|
||||
background = new Texture("background.png");
|
||||
ballT = new Texture("raw/ball.png");
|
||||
ball = new Sprite( ballT );
|
||||
}
|
||||
|
||||
public void update(){
|
||||
posX += speed * Gdx.graphics.getDeltaTime();
|
||||
if(posX + 100 > Gdx.graphics.getWidth()) speed = -speed;
|
||||
if(posX < 0) speed = -speed;
|
||||
|
||||
float Alpha = posX * 360/(2*pi*50);
|
||||
ball.setRotation(-Alpha);
|
||||
ball.setPosition(posX, 0);
|
||||
}
|
||||
|
||||
public void draw(){
|
||||
ball.draw(batch);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
update();
|
||||
batch.begin();
|
||||
batch.draw(background, 0, 0);
|
||||
draw();
|
||||
batch.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
batch.dispose();
|
||||
background.dispose();
|
||||
ballT.dispose();
|
||||
}
|
||||
}
|
||||
|
@@ -0,0 +1,98 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Boost implements Entity {
|
||||
public Array<Rectangle> entities = new Array<>();
|
||||
public float lastSpawnTime;
|
||||
public float spawnTime;
|
||||
public float width;
|
||||
public float height;
|
||||
public float speed;
|
||||
float lastX = 0;
|
||||
TextureAtlas.AtlasRegion region;
|
||||
ParticleEffect particleEffect;
|
||||
boolean spawn_bull = false;
|
||||
|
||||
public Boost(float spawnTime, float speed, float width, float height, TextureAtlas.AtlasRegion region){
|
||||
this.region = region;
|
||||
this.spawnTime = spawnTime;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.speed = speed;
|
||||
particleEffect = new ParticleEffect();
|
||||
particleEffect.load(Gdx.files.internal("effects/Boost.p"), Gdx.files.internal("effects"));
|
||||
}
|
||||
|
||||
public void checkIfSpawn(float time){
|
||||
if(!spawn_bull) {
|
||||
if (time - lastSpawnTime > spawnTime) {
|
||||
spawn_bull = true;
|
||||
lastX = MathUtils.random(0f, Global.WIDTH - width);
|
||||
particleEffect.setPosition(lastX, Global.HEIGHT);
|
||||
particleEffect.start();
|
||||
}
|
||||
}
|
||||
|
||||
if(spawn_bull){
|
||||
if(particleEffect.isComplete()){
|
||||
spawn();
|
||||
spawn_bull = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void spawn(){
|
||||
Rectangle rect = new Rectangle();
|
||||
rect.x = lastX;
|
||||
rect.y = Global.HEIGHT;
|
||||
rect.width = width;
|
||||
rect.height = height;
|
||||
entities.add(rect);
|
||||
lastSpawnTime = TimeUtils.nanosToMillis(TimeUtils.nanoTime()) / 1000f;
|
||||
}
|
||||
@Override
|
||||
public void move(){
|
||||
for (Iterator<Rectangle> it = entities.iterator(); it.hasNext(); ) {
|
||||
Rectangle rect = it.next();
|
||||
rect.y -= speed * Gdx.graphics.getDeltaTime();
|
||||
if (rect.y + rect.height < 0) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void draw(SpriteBatch batch){
|
||||
for (Rectangle rect: entities) {
|
||||
batch.draw(region, rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
particleEffect.draw(batch, Gdx.graphics.getDeltaTime());
|
||||
}
|
||||
@Override
|
||||
public void drawRect(ShapeRenderer rend){
|
||||
for (Rectangle rect: entities) {
|
||||
rend.rect(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hit(Rectangle r){
|
||||
for (Iterator<Rectangle> it = entities.iterator(); it.hasNext(); ) {
|
||||
Rectangle rect = it.next();
|
||||
if (rect.overlaps(r)) {
|
||||
it.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,72 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.ParticleEffect;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class Bullets implements Entity {
|
||||
|
||||
public Array<Rectangle> entities = new Array<>();
|
||||
public float width;
|
||||
public float height;
|
||||
ParticleEffect particleEffect;
|
||||
|
||||
int bull_x_offset = 3;
|
||||
int bull_y_offset = 20;
|
||||
int par_x_offset = 6;
|
||||
int par_y_offset = 35;
|
||||
TextureAtlas.AtlasRegion region;
|
||||
|
||||
Bullets( float width, float height, TextureAtlas.AtlasRegion region){
|
||||
this.region = region;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
particleEffect = new ParticleEffect();
|
||||
particleEffect.load(Gdx.files.internal("effects/Fire.p"), Gdx.files.internal("effects"));
|
||||
|
||||
}
|
||||
@Override
|
||||
public void spawn() {
|
||||
Rectangle rect = new Rectangle();
|
||||
rect.width = width;
|
||||
rect.height = height;
|
||||
rect.x = Global.mouse.x + bull_x_offset;
|
||||
rect.y = bull_y_offset;
|
||||
entities.add(rect);
|
||||
|
||||
particleEffect.setPosition(Global.mouse.x + par_x_offset, par_y_offset);
|
||||
particleEffect.start();
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void move() {
|
||||
for (Iterator<Rectangle> it = entities.iterator(); it.hasNext(); ) {
|
||||
Rectangle rect = it.next();
|
||||
rect.y += 200 * Gdx.graphics.getDeltaTime();
|
||||
if (rect.y > Global.HEIGHT) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(SpriteBatch batch) {
|
||||
for (Rectangle rect: entities) {
|
||||
batch.draw(region, rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
particleEffect.draw(batch,Gdx.graphics.getDeltaTime());
|
||||
}
|
||||
|
||||
public void drawRect(ShapeRenderer rend){
|
||||
for (Rectangle rect: entities) {
|
||||
rend.rect(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
}
|
||||
}
|
@@ -0,0 +1,11 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
|
||||
public interface Entity {
|
||||
void spawn();
|
||||
void move();
|
||||
void draw(SpriteBatch batch);
|
||||
void drawRect(ShapeRenderer rend);
|
||||
}
|
@@ -0,0 +1,81 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
public class FallingEntities implements Entity {
|
||||
|
||||
public Array<Rectangle> entities = new Array<>();
|
||||
public float lastSpawnTime;
|
||||
public float spawnTime;
|
||||
public float width;
|
||||
public float height;
|
||||
public float speed;
|
||||
TextureAtlas.AtlasRegion region;
|
||||
|
||||
public FallingEntities( float spawnTime, float speed, float width, float height,
|
||||
TextureAtlas.AtlasRegion region){
|
||||
this.spawnTime = spawnTime;
|
||||
this.width = width;
|
||||
this.height = height;
|
||||
this.speed = speed;
|
||||
this.region = region;
|
||||
}
|
||||
|
||||
public void checkIfSpawn(float time){
|
||||
if(time - lastSpawnTime > spawnTime){
|
||||
spawn();
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void spawn(){
|
||||
Rectangle rect = new Rectangle();
|
||||
rect.x = MathUtils.random(0f, Global.WIDTH - width);
|
||||
rect.y = Global.HEIGHT;
|
||||
rect.width = width;
|
||||
rect.height = height;
|
||||
entities.add(rect);
|
||||
lastSpawnTime = TimeUtils.nanosToMillis(TimeUtils.nanoTime()) / 1000f;
|
||||
}
|
||||
@Override
|
||||
public void move(){
|
||||
for (Iterator<Rectangle> it = entities.iterator(); it.hasNext(); ) {
|
||||
Rectangle rect = it.next();
|
||||
rect.y -= speed * Gdx.graphics.getDeltaTime();
|
||||
if (rect.y + rect.height < 0) {
|
||||
it.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void draw(SpriteBatch batch){
|
||||
for (Rectangle rect: entities) {
|
||||
batch.draw(region, rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void drawRect(ShapeRenderer rend){
|
||||
for (Rectangle rect: entities) {
|
||||
rend.rect(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
}
|
||||
|
||||
public boolean hit(Rectangle r){
|
||||
for (Iterator<Rectangle> it = entities.iterator(); it.hasNext(); ) {
|
||||
Rectangle rect = it.next();
|
||||
if (rect.overlaps(r)) {
|
||||
it.remove();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@@ -0,0 +1,9 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
|
||||
public class Global {
|
||||
public static final int WIDTH = 400;
|
||||
public static final int HEIGHT = 300;
|
||||
public static Vector3 mouse = new Vector3(0,0,0);
|
||||
}
|
@@ -0,0 +1,287 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.ApplicationAdapter;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.assets.AssetDescriptor;
|
||||
import com.badlogic.gdx.assets.AssetManager;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.GL20;
|
||||
import com.badlogic.gdx.graphics.Texture;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.GlyphLayout;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.Vector3;
|
||||
import com.badlogic.gdx.utils.Array;
|
||||
import com.badlogic.gdx.utils.TimeUtils;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.utils.viewport.FitViewport;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
|
||||
import java.util.Iterator;
|
||||
|
||||
import com.mygdx.game.util.debug.*;
|
||||
import com.mygdx.game.util.ViewportUtils;
|
||||
|
||||
public class MyGdxGame extends ApplicationAdapter {
|
||||
SpriteBatch batch;
|
||||
BitmapFont font;
|
||||
Texture background;
|
||||
Sounds sounds;
|
||||
|
||||
AssetDescriptor<TextureAtlas> descriptor;
|
||||
AssetManager manager;
|
||||
TextureAtlas atlas;
|
||||
|
||||
|
||||
Viewport viewport;
|
||||
OrthographicCamera camera;
|
||||
|
||||
DebugCameraController debugCameraController;
|
||||
MemoryInfo memoryInfo;
|
||||
ShapeRenderer shapeRenderer;
|
||||
|
||||
Array<FallingEntities> enemies;
|
||||
Player player;
|
||||
FallingEntities u_bullets;
|
||||
Bullets bullets;
|
||||
Boost boost;
|
||||
|
||||
enum State {
|
||||
PLAY,
|
||||
DEAD,
|
||||
PAUSE
|
||||
}
|
||||
State state = State.PLAY;
|
||||
public boolean debug = false;
|
||||
|
||||
|
||||
|
||||
@Override
|
||||
public void create () {
|
||||
|
||||
descriptor = new AssetDescriptor<>("packs/texture.atlas", TextureAtlas.class);
|
||||
manager = new AssetManager();
|
||||
atlas = new TextureAtlas();
|
||||
|
||||
manager.load(descriptor);
|
||||
manager.finishLoading();
|
||||
atlas = manager.get(descriptor);
|
||||
|
||||
|
||||
batch = new SpriteBatch();
|
||||
font = new BitmapFont();
|
||||
background = new Texture("raw/background.png");
|
||||
sounds = new Sounds();
|
||||
|
||||
camera = new OrthographicCamera();
|
||||
viewport = new FitViewport(Global.WIDTH, Global.HEIGHT, camera);
|
||||
|
||||
debugCameraController = new DebugCameraController();
|
||||
debugCameraController.setStartPosition(Global.WIDTH / 2f, Global.HEIGHT / 2f);
|
||||
memoryInfo = new MemoryInfo(500);
|
||||
shapeRenderer = new ShapeRenderer();
|
||||
|
||||
float sizeRatio = 1.5f;
|
||||
|
||||
enemies = new Array<>();
|
||||
enemies.add(new FallingEntities( 2.3f, 200,43/sizeRatio,49/sizeRatio, atlas.findRegion("robot")));
|
||||
enemies.add(new FallingEntities(4f, 200,43/sizeRatio,49/sizeRatio, atlas.findRegion("zombie")));
|
||||
enemies.add(new FallingEntities( 3f, 200,43/sizeRatio,49/sizeRatio, atlas.findRegion("survivor")));
|
||||
|
||||
player = new Player( 43/sizeRatio, 49/sizeRatio, atlas.findRegion("soldier"));
|
||||
u_bullets = new FallingEntities( 1f, 200, 10/sizeRatio, 10/sizeRatio, atlas.findRegion("u_bullet"));
|
||||
boost = new Boost( 1f, 400, 5/sizeRatio,5/sizeRatio, atlas.findRegion("ball"));
|
||||
bullets = new Bullets(10/sizeRatio,10/sizeRatio, atlas.findRegion("bullet"));
|
||||
}
|
||||
|
||||
void reset(){
|
||||
player.reset();
|
||||
state = State.PLAY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void resize(int width, int height) {
|
||||
viewport.update(width, height, true);
|
||||
}
|
||||
|
||||
void update(){
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.R)){
|
||||
reset();
|
||||
}
|
||||
|
||||
if(Gdx.input.isKeyJustPressed(Input.Keys.P)){
|
||||
if(state == State.PLAY){
|
||||
state = State.PAUSE;
|
||||
}else if(state == State.PAUSE){
|
||||
state = State.PLAY;
|
||||
}
|
||||
}
|
||||
|
||||
if (Gdx.input.isKeyJustPressed(Input.Keys.F1)) debug = !debug;
|
||||
|
||||
if (debug) {
|
||||
debugCameraController.handleDebugInput(Gdx.graphics.getDeltaTime());
|
||||
memoryInfo.update();
|
||||
}
|
||||
|
||||
if(state != State.PLAY) return;
|
||||
|
||||
float time = TimeUtils.nanosToMillis(TimeUtils.nanoTime()) / 1000f;
|
||||
|
||||
player.move();
|
||||
|
||||
boost.checkIfSpawn(time);
|
||||
boost.move();
|
||||
if(boost.hit(player.rect)){
|
||||
player.boost = true;
|
||||
sounds.yes.play();
|
||||
}
|
||||
|
||||
if(boost.hit(player.rect)){
|
||||
player.bullets += 5;
|
||||
sounds.reload.play();
|
||||
}
|
||||
|
||||
u_bullets.checkIfSpawn(time);
|
||||
u_bullets.move();
|
||||
if(u_bullets.hit(player.rect)){
|
||||
player.bullets++;
|
||||
sounds.reload.play();
|
||||
}
|
||||
|
||||
if(Gdx.input.isButtonJustPressed(Input.Buttons.LEFT)){
|
||||
if(player.bullets > 0){
|
||||
|
||||
bullets.spawn();
|
||||
player.bullets--;
|
||||
sounds.shot.play();
|
||||
}
|
||||
}
|
||||
bullets.move();
|
||||
|
||||
for(FallingEntities enemy: enemies){
|
||||
enemy.checkIfSpawn(time);
|
||||
enemy.move();
|
||||
if(enemy.hit(player.rect)){
|
||||
sounds.no.play();
|
||||
if(player.takeDamage()){
|
||||
state = State.DEAD;
|
||||
}
|
||||
}
|
||||
|
||||
for (Iterator<Rectangle> it = bullets.entities.iterator(); it.hasNext(); ) {
|
||||
Rectangle rect = it.next();
|
||||
if (enemy.hit(rect)) {
|
||||
it.remove();
|
||||
player.score++;
|
||||
sounds.yes.play();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void draw(){
|
||||
player.draw(batch);
|
||||
u_bullets.draw(batch);
|
||||
bullets.draw(batch);
|
||||
boost.draw(batch);
|
||||
|
||||
for(FallingEntities enemy: enemies){
|
||||
enemy.draw(batch);
|
||||
}
|
||||
|
||||
drawUI();
|
||||
}
|
||||
|
||||
void drawUI(){
|
||||
if(debug) return;
|
||||
|
||||
switch (state){
|
||||
case DEAD:
|
||||
font.setColor(Color.RED);
|
||||
font.draw(batch,"GAME OVER",20f, Global.HEIGHT - 20);
|
||||
break;
|
||||
case PAUSE:
|
||||
font.setColor(Color.YELLOW);
|
||||
font.draw(batch,"PAUSE",20f, Global.HEIGHT - 20);
|
||||
break;
|
||||
case PLAY:
|
||||
font.setColor(Color.BLUE);
|
||||
font.draw(batch, "Life: " + player.life, 20f, Global.HEIGHT - 20);
|
||||
font.draw(batch,"Bullets: " + player.bullets,20f, Global.HEIGHT - 40);
|
||||
font.draw(batch, "Score: " + player.score, 20, Global.HEIGHT - 60);
|
||||
font.draw(batch, "Boost: " + player.boost, 20, Global.HEIGHT - 80);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void drawDebug(){
|
||||
debugCameraController.applyTo(camera);
|
||||
batch.begin();
|
||||
{
|
||||
// the average number of frames per second
|
||||
GlyphLayout layout = new GlyphLayout(font, "FPS:" + Gdx.graphics.getFramesPerSecond());
|
||||
font.setColor(Color.YELLOW);
|
||||
font.draw(batch, layout, Global.WIDTH - layout.width, Global.HEIGHT - 50);
|
||||
|
||||
// number of rendering calls, ever; will not be reset unless set manually
|
||||
font.setColor(Color.YELLOW);
|
||||
font.draw(batch, "RC:" + batch.totalRenderCalls, Global.WIDTH / 2f, Global.HEIGHT - 20);
|
||||
|
||||
memoryInfo.render(batch, font);
|
||||
}
|
||||
batch.end();
|
||||
|
||||
batch.totalRenderCalls = 0;
|
||||
ViewportUtils.drawGrid(viewport, shapeRenderer, 50);
|
||||
|
||||
// print rectangles
|
||||
shapeRenderer.setProjectionMatrix(camera.combined);
|
||||
// https://libgdx.badlogicgames.com/ci/nightlies/docs/api/com/badlogic/gdx/graphics/glutils/ShapeRenderer.html
|
||||
shapeRenderer.begin(ShapeRenderer.ShapeType.Line);
|
||||
{
|
||||
shapeRenderer.setColor(1, 1, 0, 1);
|
||||
|
||||
player.drawRect(shapeRenderer);
|
||||
u_bullets.drawRect(shapeRenderer);
|
||||
bullets.drawRect(shapeRenderer);
|
||||
boost.drawRect(shapeRenderer);
|
||||
|
||||
for(FallingEntities enemy: enemies){
|
||||
enemy.drawRect(shapeRenderer);
|
||||
}
|
||||
}
|
||||
shapeRenderer.end();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void render () {
|
||||
update();
|
||||
|
||||
Gdx.gl.glClearColor(0, 0, 0f, 1);
|
||||
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
|
||||
|
||||
Global.mouse = camera.unproject(new Vector3(Gdx.input.getX(), Gdx.input.getY(), 0));
|
||||
|
||||
batch.setProjectionMatrix(camera.combined);
|
||||
batch.begin();
|
||||
batch.draw(background, 0, 0, Global.WIDTH, Global.HEIGHT);
|
||||
draw();
|
||||
batch.end();
|
||||
if(debug){
|
||||
drawDebug();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void dispose () {
|
||||
batch.dispose();
|
||||
sounds.dispose();
|
||||
font.dispose();
|
||||
background.dispose();
|
||||
}
|
||||
}
|
@@ -0,0 +1,50 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.math.Rectangle;
|
||||
|
||||
public class Player {
|
||||
|
||||
public Rectangle rect;
|
||||
int score = 0;
|
||||
int life = 5;
|
||||
int bullets = 0;
|
||||
boolean boost = false;
|
||||
TextureAtlas.AtlasRegion region;
|
||||
|
||||
public Player(float width, float height, TextureAtlas.AtlasRegion region){
|
||||
this.region = region;
|
||||
this.rect = new Rectangle();
|
||||
this.rect.x = 0;
|
||||
this.rect.y = 0;
|
||||
this.rect.width = width;
|
||||
this.rect.height = height;
|
||||
}
|
||||
|
||||
public void reset(){
|
||||
score = 0;
|
||||
life = 5;
|
||||
bullets = 0;
|
||||
}
|
||||
|
||||
public boolean takeDamage(){
|
||||
if(!boost) life--;
|
||||
else boost = false;
|
||||
|
||||
return life <= 0;
|
||||
}
|
||||
|
||||
public void move() {
|
||||
rect.x = Global.mouse.x - rect.width / 2;
|
||||
}
|
||||
|
||||
public void draw(SpriteBatch batch){
|
||||
batch.draw(region, rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
|
||||
public void drawRect(ShapeRenderer rend){
|
||||
rend.rect(rect.x, rect.y, rect.width, rect.height);
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.audio.Sound;
|
||||
import com.badlogic.gdx.utils.Disposable;
|
||||
|
||||
public class Sounds implements Disposable {
|
||||
public Sound no;
|
||||
public Sound yes;
|
||||
public Sound reload;
|
||||
public Sound shot;
|
||||
|
||||
Sounds(){
|
||||
no = Gdx.audio.newSound(Gdx.files.internal("sound/no.mp3"));
|
||||
yes = Gdx.audio.newSound(Gdx.files.internal("sound/yes.mp3"));
|
||||
reload = Gdx.audio.newSound(Gdx.files.internal("sound/reload.mp3"));
|
||||
shot = Gdx.audio.newSound(Gdx.files.internal("sound/shot.mp3"));
|
||||
}
|
||||
@Override
|
||||
public void dispose() {
|
||||
yes.dispose();
|
||||
no.dispose();
|
||||
reload.dispose();
|
||||
shot.dispose();
|
||||
}
|
||||
}
|
@@ -0,0 +1,116 @@
|
||||
package com.mygdx.game.util;
|
||||
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
|
||||
import com.badlogic.gdx.utils.Logger;
|
||||
import com.badlogic.gdx.utils.viewport.Viewport;
|
||||
|
||||
/**
|
||||
* Utility methods for using with Viewports.
|
||||
*
|
||||
* @author goran on 20/08/2016.
|
||||
*/
|
||||
public class ViewportUtils {
|
||||
|
||||
private static final Logger log = new Logger(ViewportUtils.class.getName(), Logger.DEBUG);
|
||||
|
||||
private static final int DEFAULT_CELL_SIZE = 1;
|
||||
|
||||
/**
|
||||
* Draws world grid for specified viewport using {@link ShapeRenderer}.
|
||||
*
|
||||
* @param viewport The viewports. Required.
|
||||
* @param renderer ShapeRenderer that will be used for drawing. Required.
|
||||
* @throws IllegalArgumentException if any param is nul..
|
||||
*/
|
||||
public static void drawGrid(Viewport viewport, ShapeRenderer renderer) {
|
||||
drawGrid(viewport, renderer, DEFAULT_CELL_SIZE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws world grid for specified viewport using {@link ShapeRenderer}.
|
||||
*
|
||||
* @param viewport The viewport. Required.
|
||||
* @param renderer ShapeRenderer that will be used for drawing. Required.
|
||||
* @param cellSize The size of cell in grid. If less tha 1 by default 1 will be used.
|
||||
* @throws IllegalArgumentException if any param is null.
|
||||
*/
|
||||
public static boolean drawGrid(Viewport viewport, ShapeRenderer renderer, int cellSize) {
|
||||
// validate parameters/arguments
|
||||
if (viewport == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (renderer == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (cellSize < DEFAULT_CELL_SIZE) {
|
||||
cellSize = DEFAULT_CELL_SIZE;
|
||||
}
|
||||
|
||||
// copy old color from renderer
|
||||
Color oldColor = new Color(renderer.getColor());
|
||||
|
||||
int worldWidth = (int) viewport.getWorldWidth();
|
||||
int worldHeight = (int) viewport.getWorldHeight();
|
||||
int doubleWorldWidth = worldWidth * 2;
|
||||
int doubleWorldHeight = worldHeight * 2;
|
||||
|
||||
renderer.setProjectionMatrix(viewport.getCamera().combined);
|
||||
renderer.begin(ShapeRenderer.ShapeType.Line);
|
||||
|
||||
renderer.setColor(Color.WHITE);
|
||||
|
||||
// draw vertical lines
|
||||
for (int x = -doubleWorldWidth; x < doubleWorldWidth; x += cellSize) {
|
||||
renderer.line(x, -doubleWorldHeight, x, doubleWorldHeight);
|
||||
}
|
||||
|
||||
// draw horizontal lines
|
||||
for (int y = -doubleWorldHeight; y < doubleWorldHeight; y += cellSize) {
|
||||
renderer.line(-doubleWorldWidth, y, doubleWorldWidth, y);
|
||||
}
|
||||
|
||||
// draw 0/0 lines
|
||||
renderer.setColor(Color.RED);
|
||||
renderer.line(0, -doubleWorldHeight, 0, doubleWorldHeight);
|
||||
renderer.line(-doubleWorldWidth, 0, doubleWorldWidth, 0);
|
||||
|
||||
// draw world bounds
|
||||
renderer.setColor(Color.GREEN);
|
||||
renderer.line(0, worldHeight, worldWidth, worldHeight);
|
||||
renderer.line(worldWidth, 0, worldWidth, worldHeight);
|
||||
|
||||
renderer.end();
|
||||
renderer.setColor(oldColor);
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prints pixels per unit for specified Viewport.
|
||||
*
|
||||
* @param viewport The viewport for which we want to print pixels per unit ratio. Required.
|
||||
* @throws IllegalArgumentException If viewport is null.
|
||||
*/
|
||||
public static boolean debugPixelsPerUnit(Viewport viewport) {
|
||||
if (viewport == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
float screenWidth = viewport.getScreenWidth();
|
||||
float screenHeight = viewport.getScreenHeight();
|
||||
|
||||
float worldWidth = viewport.getWorldWidth();
|
||||
float worldHeight = viewport.getWorldHeight();
|
||||
|
||||
float xPPU = screenWidth / worldWidth;
|
||||
float yPPU = screenHeight / worldHeight;
|
||||
|
||||
log.debug("x PPU = " + xPPU + " yPPU = " + yPPU);
|
||||
return true;
|
||||
}
|
||||
|
||||
private ViewportUtils() {
|
||||
}
|
||||
}
|
@@ -0,0 +1,164 @@
|
||||
package com.mygdx.game.util.debug;
|
||||
|
||||
import com.badlogic.gdx.Application;
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.OrthographicCamera;
|
||||
import com.badlogic.gdx.math.MathUtils;
|
||||
import com.badlogic.gdx.math.Vector2;
|
||||
import com.badlogic.gdx.utils.Logger;
|
||||
|
||||
/**
|
||||
* Controller for debugging {@link OrthographicCamera}.
|
||||
*
|
||||
* @author goran on 22/08/2016.
|
||||
*/
|
||||
public class DebugCameraController {
|
||||
|
||||
// == constants ==
|
||||
private static final Logger log = new Logger(DebugCameraController.class.getName(), Logger.DEBUG);
|
||||
|
||||
// == attributes ==
|
||||
private final Vector2 position = new Vector2();
|
||||
private final Vector2 startPosition = new Vector2();
|
||||
private float zoom = 1.0f;
|
||||
private DebugCameraInfo info;
|
||||
|
||||
// == constructors ==
|
||||
public DebugCameraController() {
|
||||
init();
|
||||
}
|
||||
|
||||
// == init ==
|
||||
private void init() {
|
||||
info = new DebugCameraInfo();
|
||||
|
||||
log.info("cameraInfo = " + info);
|
||||
}
|
||||
|
||||
// == public methods ==
|
||||
|
||||
/**
|
||||
* Sets start position of camera.
|
||||
*
|
||||
* @param x The x position.
|
||||
* @param y The y position.
|
||||
*/
|
||||
public void setStartPosition(float x, float y) {
|
||||
startPosition.set(x, y);
|
||||
setPosition(x, y);
|
||||
}
|
||||
|
||||
/**
|
||||
* Applies internal position and zoom to specified camera.
|
||||
* Call this method after handling debug input.
|
||||
*
|
||||
* @param camera camera The camera instance.
|
||||
* @throws IllegalArgumentException if camera param is null.
|
||||
* @see #handleDebugInput(float)
|
||||
*/
|
||||
public boolean applyTo(OrthographicCamera camera) {
|
||||
if (camera == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
camera.position.set(position, 0);
|
||||
camera.zoom = zoom;
|
||||
camera.update();
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Handles debug input. Call this in your update cycle.
|
||||
*
|
||||
* @param delta The delta time.
|
||||
*/
|
||||
public void handleDebugInput(float delta) {
|
||||
if (Gdx.app.getType() != Application.ApplicationType.Desktop) {
|
||||
return;
|
||||
}
|
||||
|
||||
float moveSpeed = info.getMoveSpeed() * delta;
|
||||
float zoomSpeed = info.getZoomSpeed() * delta;
|
||||
|
||||
// move control
|
||||
if (info.isLeftPressed()) {
|
||||
moveLeft(moveSpeed);
|
||||
}
|
||||
|
||||
if (info.isRightPressed()) {
|
||||
moveRight(moveSpeed);
|
||||
}
|
||||
|
||||
if (info.isUpPressed()) {
|
||||
moveUp(moveSpeed);
|
||||
}
|
||||
|
||||
if (info.isDownPressed()) {
|
||||
moveDown(moveSpeed);
|
||||
}
|
||||
|
||||
// zoom control
|
||||
if (info.isZoomInPressed()) {
|
||||
zoomIn(zoomSpeed);
|
||||
}
|
||||
if (info.isZoomOutPressed()) {
|
||||
zoomOut(zoomSpeed);
|
||||
}
|
||||
|
||||
// reset control
|
||||
if (info.isResetPressed()) {
|
||||
reset();
|
||||
}
|
||||
|
||||
// log control
|
||||
if (info.isLogPressed()) {
|
||||
logDebug();
|
||||
}
|
||||
}
|
||||
|
||||
// == private methods ==
|
||||
private void setPosition(float x, float y) {
|
||||
position.set(x, y);
|
||||
}
|
||||
|
||||
private void setZoom(float value) {
|
||||
zoom = MathUtils.clamp(value, info.getMaxZoomIn(), info.getMaxZoomOut());
|
||||
}
|
||||
|
||||
private void moveCamera(float xSpeed, float ySpeed) {
|
||||
setPosition(position.x + xSpeed, position.y + ySpeed);
|
||||
}
|
||||
|
||||
private void moveLeft(float speed) {
|
||||
moveCamera(-speed, 0);
|
||||
}
|
||||
|
||||
private void moveRight(float speed) {
|
||||
moveCamera(speed, 0);
|
||||
}
|
||||
|
||||
private void moveUp(float speed) {
|
||||
moveCamera(0, speed);
|
||||
}
|
||||
|
||||
private void moveDown(float speed) {
|
||||
moveCamera(0, -speed);
|
||||
}
|
||||
|
||||
private void zoomIn(float zoomSpeed) {
|
||||
setZoom(zoom + zoomSpeed);
|
||||
}
|
||||
|
||||
private void zoomOut(float zoomSpeed) {
|
||||
setZoom(zoom - zoomSpeed);
|
||||
}
|
||||
|
||||
private void reset() {
|
||||
position.set(startPosition);
|
||||
setZoom(1.0f);
|
||||
}
|
||||
|
||||
private void logDebug() {
|
||||
log.debug("position = " + position + " zoom = " + zoom);
|
||||
}
|
||||
}
|
@@ -0,0 +1,208 @@
|
||||
package com.mygdx.game.util.debug;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.Input;
|
||||
import com.badlogic.gdx.files.FileHandle;
|
||||
import com.badlogic.gdx.utils.JsonReader;
|
||||
import com.badlogic.gdx.utils.JsonValue;
|
||||
import com.badlogic.gdx.utils.Logger;
|
||||
|
||||
/**
|
||||
* Info/Configuration for {@link DebugCameraController}.
|
||||
* Loads configuration from file in assetsDir/debug/debug-camera.json
|
||||
*
|
||||
* @author goran on 22/08/2016.
|
||||
*/
|
||||
public class DebugCameraInfo {
|
||||
|
||||
// == constants ==
|
||||
private static final Logger log = new Logger(DebugCameraInfo.class.getName(), Logger.DEBUG);
|
||||
|
||||
private static final String MAX_ZOOM_IN = "maxZoomIn";
|
||||
private static final String MAX_ZOOM_OUT = "maxZoomOut";
|
||||
private static final String MOVE_SPEED = "moveSpeed";
|
||||
private static final String ZOOM_SPEED = "zoomSpeed";
|
||||
|
||||
private static final String LEFT_KEY = "leftKey";
|
||||
private static final String RIGHT_KEY = "rightKey";
|
||||
private static final String UP_KEY = "upKey";
|
||||
private static final String DOWN_KEY = "downKey";
|
||||
|
||||
private static final String ZOOM_IN_KEY = "zoomInKey";
|
||||
private static final String ZOOM_OUT_KEY = "zoomOutKey";
|
||||
private static final String RESET_KEY = "resetKey";
|
||||
private static final String LOG_KEY = "logKey";
|
||||
|
||||
private static final int DEFAULT_LEFT_KEY = Input.Keys.A;
|
||||
private static final int DEFAULT_RIGHT_KEY = Input.Keys.D;
|
||||
private static final int DEFAULT_UP_KEY = Input.Keys.W;
|
||||
private static final int DEFAULT_DOWN_KEY = Input.Keys.S;
|
||||
|
||||
private static final int DEFAULT_ZOOM_IN_KEY = Input.Keys.COMMA;
|
||||
private static final int DEFAULT_ZOOM_OUT_KEY = Input.Keys.PERIOD;
|
||||
|
||||
private static final int DEFAULT_RESET_KEY = Input.Keys.BACKSPACE;
|
||||
private static final int DEFAULT_LOG_KEY = Input.Keys.ENTER;
|
||||
|
||||
private static final float DEFAULT_MOVE_SPEED = 20.0f;
|
||||
private static final float DEFAULT_ZOOM_SPEED = 2.0f;
|
||||
private static final float DEFAULT_MAX_ZOOM_IN = 0.25f;
|
||||
private static final float DEFAULT_MAX_ZOOM_OUT = 30f;
|
||||
|
||||
private final String FILE_PATH = "debug/debugCameraInfo.json";
|
||||
|
||||
// == attributes ==
|
||||
private float maxZoomIn;
|
||||
private float maxZoomOut;
|
||||
private float moveSpeed;
|
||||
private float zoomSpeed;
|
||||
|
||||
private int leftKey;
|
||||
private int rightKey;
|
||||
private int upKey;
|
||||
private int downKey;
|
||||
|
||||
private int zoomInKey;
|
||||
private int zoomOutKey;
|
||||
|
||||
private int resetKey;
|
||||
private int logKey;
|
||||
|
||||
private FileHandle fileHandle;
|
||||
|
||||
// == constructors ==
|
||||
public DebugCameraInfo() {
|
||||
init();
|
||||
}
|
||||
|
||||
// == init ==
|
||||
private void init() {
|
||||
fileHandle = Gdx.files.internal(FILE_PATH);
|
||||
|
||||
if (fileHandle.exists()) {
|
||||
load();
|
||||
} else {
|
||||
log.info("Using defaults file does not exist = " + FILE_PATH);
|
||||
setupDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
// == private methods ==
|
||||
private void load() {
|
||||
try {
|
||||
JsonReader reader = new JsonReader();
|
||||
JsonValue root = reader.parse(fileHandle);
|
||||
|
||||
maxZoomIn = root.getFloat(MAX_ZOOM_IN, DEFAULT_MAX_ZOOM_IN);
|
||||
maxZoomOut = root.getFloat(MAX_ZOOM_OUT, DEFAULT_MAX_ZOOM_OUT);
|
||||
moveSpeed = root.getFloat(MOVE_SPEED, DEFAULT_MOVE_SPEED);
|
||||
zoomSpeed = root.getFloat(ZOOM_SPEED, DEFAULT_ZOOM_SPEED);
|
||||
|
||||
leftKey = getInputKeyValue(root, LEFT_KEY, DEFAULT_LEFT_KEY);
|
||||
rightKey = getInputKeyValue(root, RIGHT_KEY, DEFAULT_RIGHT_KEY);
|
||||
upKey = getInputKeyValue(root, UP_KEY, DEFAULT_UP_KEY);
|
||||
downKey = getInputKeyValue(root, DOWN_KEY, DEFAULT_DOWN_KEY);
|
||||
|
||||
zoomInKey = getInputKeyValue(root, ZOOM_IN_KEY, DEFAULT_ZOOM_IN_KEY);
|
||||
zoomOutKey = getInputKeyValue(root, ZOOM_OUT_KEY, DEFAULT_ZOOM_OUT_KEY);
|
||||
resetKey = getInputKeyValue(root, RESET_KEY, DEFAULT_RESET_KEY);
|
||||
logKey = getInputKeyValue(root, LOG_KEY, DEFAULT_LOG_KEY);
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("Error loading " + FILE_PATH + " using defaults.", e);
|
||||
setupDefaults();
|
||||
}
|
||||
}
|
||||
|
||||
private void setupDefaults() {
|
||||
maxZoomIn = DEFAULT_MAX_ZOOM_IN;
|
||||
maxZoomOut = DEFAULT_MAX_ZOOM_OUT;
|
||||
moveSpeed = DEFAULT_MOVE_SPEED;
|
||||
zoomSpeed = DEFAULT_ZOOM_SPEED;
|
||||
|
||||
leftKey = DEFAULT_LEFT_KEY;
|
||||
rightKey = DEFAULT_RIGHT_KEY;
|
||||
upKey = DEFAULT_UP_KEY;
|
||||
downKey = DEFAULT_DOWN_KEY;
|
||||
|
||||
zoomInKey = DEFAULT_ZOOM_IN_KEY;
|
||||
zoomOutKey = DEFAULT_ZOOM_OUT_KEY;
|
||||
resetKey = DEFAULT_RESET_KEY;
|
||||
logKey = DEFAULT_LOG_KEY;
|
||||
}
|
||||
|
||||
// == public methods ==
|
||||
public float getMaxZoomIn() {
|
||||
return maxZoomIn;
|
||||
}
|
||||
|
||||
public float getMaxZoomOut() {
|
||||
return maxZoomOut;
|
||||
}
|
||||
|
||||
public float getMoveSpeed() {
|
||||
return moveSpeed;
|
||||
}
|
||||
|
||||
public float getZoomSpeed() {
|
||||
return zoomSpeed;
|
||||
}
|
||||
|
||||
public boolean isLeftPressed() {
|
||||
return Gdx.input.isKeyPressed(leftKey);
|
||||
}
|
||||
|
||||
public boolean isRightPressed() {
|
||||
return Gdx.input.isKeyPressed(rightKey);
|
||||
}
|
||||
|
||||
public boolean isUpPressed() {
|
||||
return Gdx.input.isKeyPressed(upKey);
|
||||
}
|
||||
|
||||
public boolean isDownPressed() {
|
||||
return Gdx.input.isKeyPressed(downKey);
|
||||
}
|
||||
|
||||
public boolean isZoomInPressed() {
|
||||
return Gdx.input.isKeyPressed(zoomInKey);
|
||||
}
|
||||
|
||||
public boolean isZoomOutPressed() {
|
||||
return Gdx.input.isKeyPressed(zoomOutKey);
|
||||
}
|
||||
|
||||
public boolean isResetPressed() {
|
||||
return Gdx.input.isKeyPressed(resetKey);
|
||||
}
|
||||
|
||||
public boolean isLogPressed() {
|
||||
return Gdx.input.isKeyPressed(logKey);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String LS = System.getProperty("line.separator");
|
||||
|
||||
return "DebugCameraInfo {" + LS +
|
||||
"maxZoomIn= " + maxZoomIn + LS +
|
||||
"maxZoomOut= " + maxZoomOut + LS +
|
||||
"moveSpeed= " + moveSpeed + LS +
|
||||
"zoomSpeed= " + zoomSpeed + LS +
|
||||
"leftKey= " + Input.Keys.toString(leftKey) + LS +
|
||||
"rightKey= " + Input.Keys.toString(rightKey) + LS +
|
||||
"upKey= " + Input.Keys.toString(upKey) + LS +
|
||||
"downKey= " + Input.Keys.toString(downKey) + LS +
|
||||
"zoomInKey= " + Input.Keys.toString(zoomInKey) + LS +
|
||||
"zoomOutKey= " + Input.Keys.toString(zoomOutKey) + LS +
|
||||
"resetKey= " + Input.Keys.toString(resetKey) + LS +
|
||||
"logKey= " + Input.Keys.toString(logKey) + LS +
|
||||
"}";
|
||||
}
|
||||
|
||||
// == static methods ==
|
||||
private static int getInputKeyValue(JsonValue root, String name, int defaultInputKey) {
|
||||
String keyString = root.getString(name, Input.Keys.toString(defaultInputKey));
|
||||
return Input.Keys.valueOf(keyString);
|
||||
}
|
||||
}
|
@@ -0,0 +1,55 @@
|
||||
package com.mygdx.game.util.debug;
|
||||
|
||||
import com.badlogic.gdx.Gdx;
|
||||
import com.badlogic.gdx.graphics.Color;
|
||||
import com.badlogic.gdx.graphics.g2d.BitmapFont;
|
||||
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
|
||||
|
||||
public class MemoryInfo {
|
||||
public static final long MB = 1024 * 1024;
|
||||
private final Runtime instance;
|
||||
private final long updateIntervalMs;
|
||||
private long lastUpdate;
|
||||
private long totalMemory; // total amount of memory in the Java virtual machine
|
||||
private long freeMemory; // amount of free memory in the Java Virtual Machine
|
||||
private long usedMemory;
|
||||
private long maxMemory; // maximum amount of memory that the Java virtual machine will attempt to use
|
||||
private long javaHeap; // Java heap memory use in bytes
|
||||
private long nativeHeap; // native heap memory use in bytes
|
||||
|
||||
public MemoryInfo(long updateIntervalMs) {
|
||||
instance = Runtime.getRuntime();
|
||||
this.updateIntervalMs = updateIntervalMs;
|
||||
lastUpdate = 0;
|
||||
update();
|
||||
}
|
||||
|
||||
public void update() {
|
||||
if ((lastUpdate + updateIntervalMs) < System.currentTimeMillis()) {
|
||||
totalMemory = instance.totalMemory() / MB;
|
||||
freeMemory = instance.freeMemory() / MB;
|
||||
usedMemory = instance.totalMemory() / MB - freeMemory;
|
||||
maxMemory = instance.maxMemory() / MB;
|
||||
javaHeap = Gdx.app.getJavaHeap() / MB;
|
||||
nativeHeap = Gdx.app.getNativeHeap() / MB;
|
||||
lastUpdate = System.currentTimeMillis();
|
||||
}
|
||||
}
|
||||
|
||||
public void render(SpriteBatch batch, BitmapFont font) {
|
||||
float positionY = 100 + font.getCapHeight();
|
||||
font.setColor(Color.WHITE);
|
||||
font.draw(batch, "totalMemory:" + totalMemory + " mb", 20, positionY);
|
||||
positionY += font.getCapHeight() + 10;
|
||||
font.draw(batch, "freeMemory :" + freeMemory + " mb", 20, positionY);
|
||||
positionY += font.getCapHeight() + 10;
|
||||
font.draw(batch, "usedMemory :" + usedMemory + " mb", 20, positionY);
|
||||
positionY += font.getCapHeight() + 10;
|
||||
font.draw(batch, "maxMemory :" + maxMemory + " mb", 20, positionY);
|
||||
positionY += font.getCapHeight() + 10;
|
||||
font.draw(batch, "javaHeap :" + javaHeap + " mb", 20, positionY);
|
||||
positionY += font.getCapHeight() + 10;
|
||||
font.draw(batch, "nativeHeap :" + nativeHeap + " mb", 20, positionY);
|
||||
positionY += font.getCapHeight() + 10;
|
||||
}
|
||||
}
|
@@ -0,0 +1,49 @@
|
||||
sourceCompatibility = 1.8
|
||||
sourceSets.main.java.srcDirs = [ "src/" ]
|
||||
sourceSets.main.resources.srcDirs = ["../assets"]
|
||||
|
||||
project.ext.mainClassName = "com.mygdx.game.DesktopLauncher"
|
||||
project.ext.assetsDir = new File("../assets")
|
||||
|
||||
import org.gradle.internal.os.OperatingSystem
|
||||
|
||||
tasks.register('run', JavaExec) {
|
||||
dependsOn classes
|
||||
mainClass = project.mainClassName
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = project.assetsDir
|
||||
ignoreExitValue = true
|
||||
|
||||
if (OperatingSystem.current() == OperatingSystem.MAC_OS) {
|
||||
// Required to run on macOS
|
||||
jvmArgs += "-XstartOnFirstThread"
|
||||
}
|
||||
}
|
||||
|
||||
tasks.register('debug', JavaExec) {
|
||||
dependsOn classes
|
||||
mainClass = project.mainClassName
|
||||
classpath = sourceSets.main.runtimeClasspath
|
||||
standardInput = System.in
|
||||
workingDir = project.assetsDir
|
||||
ignoreExitValue = true
|
||||
debug = true
|
||||
}
|
||||
|
||||
tasks.register('dist', Jar) {
|
||||
duplicatesStrategy(DuplicatesStrategy.EXCLUDE)
|
||||
manifest {
|
||||
attributes 'Main-Class': project.mainClassName
|
||||
}
|
||||
dependsOn configurations.runtimeClasspath
|
||||
from {
|
||||
configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) }
|
||||
}
|
||||
with jar
|
||||
}
|
||||
|
||||
|
||||
dist.dependsOn classes
|
||||
|
||||
eclipse.project.name = appName + "-desktop"
|
@@ -0,0 +1,14 @@
|
||||
package com.mygdx.BouncingBalls;
|
||||
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
|
||||
// Please note that on macOS your application needs to be started with the -XstartOnFirstThread JVM argument
|
||||
public class DesktopLauncher {
|
||||
public static void main (String[] arg) {
|
||||
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
|
||||
config.setForegroundFPS(60);
|
||||
config.setTitle("bouncing_balls");
|
||||
new Lwjgl3Application(new Game(), config);
|
||||
}
|
||||
}
|
@@ -0,0 +1,15 @@
|
||||
package com.mygdx.MyTexturePacker;
|
||||
|
||||
import com.badlogic.gdx.tools.texturepacker.TexturePacker;
|
||||
|
||||
public class Packer {
|
||||
public static void main(String[] args){
|
||||
TexturePacker.Settings settings = new TexturePacker.Settings();
|
||||
settings.debug = false;
|
||||
settings.maxHeight = 2048;
|
||||
settings.maxWidth = 2048;
|
||||
|
||||
TexturePacker.process(settings, "assets/raw/", "assets/packs/", "texture");
|
||||
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.mygdx.RotatingBall;
|
||||
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
|
||||
// Please note that on macOS your application needs to be started with the -XstartOnFirstThread JVM argument
|
||||
public class DesktopLauncher {
|
||||
public static void main (String[] arg) {
|
||||
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
|
||||
config.setForegroundFPS(60);
|
||||
config.setTitle("RotatingBall");
|
||||
new Lwjgl3Application(new Game(), config);
|
||||
}
|
||||
}
|
@@ -0,0 +1,14 @@
|
||||
package com.mygdx.game;
|
||||
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3Application;
|
||||
import com.badlogic.gdx.backends.lwjgl3.Lwjgl3ApplicationConfiguration;
|
||||
// Please note that on macOS your application needs to be started with the -XstartOnFirstThread JVM argument
|
||||
public class DesktopLauncher {
|
||||
public static void main (String[] arg) {
|
||||
Lwjgl3ApplicationConfiguration config = new Lwjgl3ApplicationConfiguration();
|
||||
config.setForegroundFPS(60);
|
||||
config.setTitle("My GDX");
|
||||
config.setWindowedMode(800, 600);
|
||||
new Lwjgl3Application(new MyGdxGame(), config);
|
||||
}
|
||||
}
|
@@ -0,0 +1,3 @@
|
||||
org.gradle.daemon=true
|
||||
org.gradle.jvmargs=-Xms128m -Xmx1500m
|
||||
org.gradle.configureondemand=false
|
BIN
semester_5/uvod_v_razvoj_racunalniskih_iger/game_1/gradle/wrapper/gradle-wrapper.jar
vendored
Normal file
5
semester_5/uvod_v_razvoj_racunalniskih_iger/game_1/gradle/wrapper/gradle-wrapper.properties
vendored
Normal file
@@ -0,0 +1,5 @@
|
||||
distributionBase=GRADLE_USER_HOME
|
||||
distributionPath=wrapper/dists
|
||||
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-bin.zip
|
||||
zipStoreBase=GRADLE_USER_HOME
|
||||
zipStorePath=wrapper/dists
|
240
semester_5/uvod_v_razvoj_racunalniskih_iger/game_1/gradlew
vendored
Executable file
@@ -0,0 +1,240 @@
|
||||
#!/bin/sh
|
||||
|
||||
#
|
||||
# Copyright © 2015-2021 the original authors.
|
||||
#
|
||||
# Licensed under the Apache License, Version 2.0 (the "License");
|
||||
# you may not use this file except in compliance with the License.
|
||||
# You may obtain a copy of the License at
|
||||
#
|
||||
# https://www.apache.org/licenses/LICENSE-2.0
|
||||
#
|
||||
# Unless required by applicable law or agreed to in writing, software
|
||||
# distributed under the License is distributed on an "AS IS" BASIS,
|
||||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
# See the License for the specific language governing permissions and
|
||||
# limitations under the License.
|
||||
#
|
||||
|
||||
##############################################################################
|
||||
#
|
||||
# Gradle start up script for POSIX generated by Gradle.
|
||||
#
|
||||
# Important for running:
|
||||
#
|
||||
# (1) You need a POSIX-compliant shell to run this script. If your /bin/sh is
|
||||
# noncompliant, but you have some other compliant shell such as ksh or
|
||||
# bash, then to run this script, type that shell name before the whole
|
||||
# command line, like:
|
||||
#
|
||||
# ksh Gradle
|
||||
#
|
||||
# Busybox and similar reduced shells will NOT work, because this script
|
||||
# requires all of these POSIX shell features:
|
||||
# * functions;
|
||||
# * expansions «$var», «${var}», «${var:-default}», «${var+SET}»,
|
||||
# «${var#prefix}», «${var%suffix}», and «$( cmd )»;
|
||||
# * compound commands having a testable exit status, especially «case»;
|
||||
# * various built-in commands including «command», «set», and «ulimit».
|
||||
#
|
||||
# Important for patching:
|
||||
#
|
||||
# (2) This script targets any POSIX shell, so it avoids extensions provided
|
||||
# by Bash, Ksh, etc; in particular arrays are avoided.
|
||||
#
|
||||
# The "traditional" practice of packing multiple parameters into a
|
||||
# space-separated string is a well documented source of bugs and security
|
||||
# problems, so this is (mostly) avoided, by progressively accumulating
|
||||
# options in "$@", and eventually passing that to Java.
|
||||
#
|
||||
# Where the inherited environment variables (DEFAULT_JVM_OPTS, JAVA_OPTS,
|
||||
# and GRADLE_OPTS) rely on word-splitting, this is performed explicitly;
|
||||
# see the in-line comments for details.
|
||||
#
|
||||
# There are tweaks for specific operating systems such as AIX, CygWin,
|
||||
# Darwin, MinGW, and NonStop.
|
||||
#
|
||||
# (3) This script is generated from the Groovy template
|
||||
# https://github.com/gradle/gradle/blob/master/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
|
||||
# within the Gradle project.
|
||||
#
|
||||
# You can find Gradle at https://github.com/gradle/gradle/.
|
||||
#
|
||||
##############################################################################
|
||||
|
||||
# Attempt to set APP_HOME
|
||||
|
||||
# Resolve links: $0 may be a link
|
||||
app_path=$0
|
||||
|
||||
# Need this for daisy-chained symlinks.
|
||||
while
|
||||
APP_HOME=${app_path%"${app_path##*/}"} # leaves a trailing /; empty if no leading path
|
||||
[ -h "$app_path" ]
|
||||
do
|
||||
ls=$( ls -ld "$app_path" )
|
||||
link=${ls#*' -> '}
|
||||
case $link in #(
|
||||
/*) app_path=$link ;; #(
|
||||
*) app_path=$APP_HOME$link ;;
|
||||
esac
|
||||
done
|
||||
|
||||
APP_HOME=$( cd "${APP_HOME:-./}" && pwd -P ) || exit
|
||||
|
||||
APP_NAME="Gradle"
|
||||
APP_BASE_NAME=${0##*/}
|
||||
|
||||
# Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
DEFAULT_JVM_OPTS='"-Xmx64m" "-Xms64m"'
|
||||
|
||||
# Use the maximum available, or set MAX_FD != -1 to use that value.
|
||||
MAX_FD=maximum
|
||||
|
||||
warn () {
|
||||
echo "$*"
|
||||
} >&2
|
||||
|
||||
die () {
|
||||
echo
|
||||
echo "$*"
|
||||
echo
|
||||
exit 1
|
||||
} >&2
|
||||
|
||||
# OS specific support (must be 'true' or 'false').
|
||||
cygwin=false
|
||||
msys=false
|
||||
darwin=false
|
||||
nonstop=false
|
||||
case "$( uname )" in #(
|
||||
CYGWIN* ) cygwin=true ;; #(
|
||||
Darwin* ) darwin=true ;; #(
|
||||
MSYS* | MINGW* ) msys=true ;; #(
|
||||
NONSTOP* ) nonstop=true ;;
|
||||
esac
|
||||
|
||||
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
|
||||
|
||||
|
||||
# Determine the Java command to use to start the JVM.
|
||||
if [ -n "$JAVA_HOME" ] ; then
|
||||
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
|
||||
# IBM's JDK on AIX uses strange locations for the executables
|
||||
JAVACMD=$JAVA_HOME/jre/sh/java
|
||||
else
|
||||
JAVACMD=$JAVA_HOME/bin/java
|
||||
fi
|
||||
if [ ! -x "$JAVACMD" ] ; then
|
||||
die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
else
|
||||
JAVACMD=java
|
||||
which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
|
||||
Please set the JAVA_HOME variable in your environment to match the
|
||||
location of your Java installation."
|
||||
fi
|
||||
|
||||
# Increase the maximum file descriptors if we can.
|
||||
if ! "$cygwin" && ! "$darwin" && ! "$nonstop" ; then
|
||||
case $MAX_FD in #(
|
||||
max*)
|
||||
MAX_FD=$( ulimit -H -n ) ||
|
||||
warn "Could not query maximum file descriptor limit"
|
||||
esac
|
||||
case $MAX_FD in #(
|
||||
'' | soft) :;; #(
|
||||
*)
|
||||
ulimit -n "$MAX_FD" ||
|
||||
warn "Could not set maximum file descriptor limit to $MAX_FD"
|
||||
esac
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command, stacking in reverse order:
|
||||
# * args from the command line
|
||||
# * the main class name
|
||||
# * -classpath
|
||||
# * -D...appname settings
|
||||
# * --module-path (only if needed)
|
||||
# * DEFAULT_JVM_OPTS, JAVA_OPTS, and GRADLE_OPTS environment variables.
|
||||
|
||||
# For Cygwin or MSYS, switch paths to Windows format before running java
|
||||
if "$cygwin" || "$msys" ; then
|
||||
APP_HOME=$( cygpath --path --mixed "$APP_HOME" )
|
||||
CLASSPATH=$( cygpath --path --mixed "$CLASSPATH" )
|
||||
|
||||
JAVACMD=$( cygpath --unix "$JAVACMD" )
|
||||
|
||||
# Now convert the arguments - kludge to limit ourselves to /bin/sh
|
||||
for arg do
|
||||
if
|
||||
case $arg in #(
|
||||
-*) false ;; # don't mess with options #(
|
||||
/?*) t=${arg#/} t=/${t%%/*} # looks like a POSIX filepath
|
||||
[ -e "$t" ] ;; #(
|
||||
*) false ;;
|
||||
esac
|
||||
then
|
||||
arg=$( cygpath --path --ignore --mixed "$arg" )
|
||||
fi
|
||||
# Roll the args list around exactly as many times as the number of
|
||||
# args, so each arg winds up back in the position where it started, but
|
||||
# possibly modified.
|
||||
#
|
||||
# NB: a `for` loop captures its iteration list before it begins, so
|
||||
# changing the positional parameters here affects neither the number of
|
||||
# iterations, nor the values presented in `arg`.
|
||||
shift # remove old arg
|
||||
set -- "$@" "$arg" # push replacement arg
|
||||
done
|
||||
fi
|
||||
|
||||
# Collect all arguments for the java command;
|
||||
# * $DEFAULT_JVM_OPTS, $JAVA_OPTS, and $GRADLE_OPTS can contain fragments of
|
||||
# shell script including quotes and variable substitutions, so put them in
|
||||
# double quotes to make sure that they get re-expanded; and
|
||||
# * put everything else in single quotes, so that it's not re-expanded.
|
||||
|
||||
set -- \
|
||||
"-Dorg.gradle.appname=$APP_BASE_NAME" \
|
||||
-classpath "$CLASSPATH" \
|
||||
org.gradle.wrapper.GradleWrapperMain \
|
||||
"$@"
|
||||
|
||||
# Stop when "xargs" is not available.
|
||||
if ! command -v xargs >/dev/null 2>&1
|
||||
then
|
||||
die "xargs is not available"
|
||||
fi
|
||||
|
||||
# Use "xargs" to parse quoted args.
|
||||
#
|
||||
# With -n1 it outputs one arg per line, with the quotes and backslashes removed.
|
||||
#
|
||||
# In Bash we could simply go:
|
||||
#
|
||||
# readarray ARGS < <( xargs -n1 <<<"$var" ) &&
|
||||
# set -- "${ARGS[@]}" "$@"
|
||||
#
|
||||
# but POSIX shell has neither arrays nor command substitution, so instead we
|
||||
# post-process each arg (as a line of input to sed) to backslash-escape any
|
||||
# character that might be a shell metacharacter, then use eval to reverse
|
||||
# that process (while maintaining the separation between arguments), and wrap
|
||||
# the whole thing up as a single "set" statement.
|
||||
#
|
||||
# This will of course break if any of these variables contains a newline or
|
||||
# an unmatched quote.
|
||||
#
|
||||
|
||||
eval "set -- $(
|
||||
printf '%s\n' "$DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS" |
|
||||
xargs -n1 |
|
||||
sed ' s~[^-[:alnum:]+,./:=@_]~\\&~g; ' |
|
||||
tr '\n' ' '
|
||||
)" '"$@"'
|
||||
|
||||
exec "$JAVACMD" "$@"
|
91
semester_5/uvod_v_razvoj_racunalniskih_iger/game_1/gradlew.bat
vendored
Normal file
@@ -0,0 +1,91 @@
|
||||
@rem
|
||||
@rem Copyright 2015 the original author or authors.
|
||||
@rem
|
||||
@rem Licensed under the Apache License, Version 2.0 (the "License");
|
||||
@rem you may not use this file except in compliance with the License.
|
||||
@rem You may obtain a copy of the License at
|
||||
@rem
|
||||
@rem https://www.apache.org/licenses/LICENSE-2.0
|
||||
@rem
|
||||
@rem Unless required by applicable law or agreed to in writing, software
|
||||
@rem distributed under the License is distributed on an "AS IS" BASIS,
|
||||
@rem WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
@rem See the License for the specific language governing permissions and
|
||||
@rem limitations under the License.
|
||||
@rem
|
||||
|
||||
@if "%DEBUG%"=="" @echo off
|
||||
@rem ##########################################################################
|
||||
@rem
|
||||
@rem Gradle startup script for Windows
|
||||
@rem
|
||||
@rem ##########################################################################
|
||||
|
||||
@rem Set local scope for the variables with windows NT shell
|
||||
if "%OS%"=="Windows_NT" setlocal
|
||||
|
||||
set DIRNAME=%~dp0
|
||||
if "%DIRNAME%"=="" set DIRNAME=.
|
||||
set APP_BASE_NAME=%~n0
|
||||
set APP_HOME=%DIRNAME%
|
||||
|
||||
@rem Resolve any "." and ".." in APP_HOME to make it shorter.
|
||||
for %%i in ("%APP_HOME%") do set APP_HOME=%%~fi
|
||||
|
||||
@rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script.
|
||||
set DEFAULT_JVM_OPTS="-Xmx64m" "-Xms64m"
|
||||
|
||||
@rem Find java.exe
|
||||
if defined JAVA_HOME goto findJavaFromJavaHome
|
||||
|
||||
set JAVA_EXE=java.exe
|
||||
%JAVA_EXE% -version >NUL 2>&1
|
||||
if %ERRORLEVEL% equ 0 goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH.
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:findJavaFromJavaHome
|
||||
set JAVA_HOME=%JAVA_HOME:"=%
|
||||
set JAVA_EXE=%JAVA_HOME%/bin/java.exe
|
||||
|
||||
if exist "%JAVA_EXE%" goto execute
|
||||
|
||||
echo.
|
||||
echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME%
|
||||
echo.
|
||||
echo Please set the JAVA_HOME variable in your environment to match the
|
||||
echo location of your Java installation.
|
||||
|
||||
goto fail
|
||||
|
||||
:execute
|
||||
@rem Setup the command line
|
||||
|
||||
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
|
||||
|
||||
|
||||
@rem Execute Gradle
|
||||
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %*
|
||||
|
||||
:end
|
||||
@rem End local scope for the variables with windows NT shell
|
||||
if %ERRORLEVEL% equ 0 goto mainEnd
|
||||
|
||||
:fail
|
||||
rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of
|
||||
rem the _cmd.exe /c_ return code!
|
||||
set EXIT_CODE=%ERRORLEVEL%
|
||||
if %EXIT_CODE% equ 0 set EXIT_CODE=1
|
||||
if not ""=="%GRADLE_EXIT_CONSOLE%" exit %EXIT_CODE%
|
||||
exit /b %EXIT_CODE%
|
||||
|
||||
:mainEnd
|
||||
if "%OS%"=="Windows_NT" endlocal
|
||||
|
||||
:omega
|
@@ -0,0 +1 @@
|
||||
include 'desktop', 'core'
|