Skip to content
Snippets Groups Projects
Commit 34a2a4e2 authored by Karin Sofie Syversveen Lie's avatar Karin Sofie Syversveen Lie
Browse files

Merge branch 'create-movement' into 'master'

Create movement

See merge request !1
parents a6dd5d72 1bf5c4d6
No related branches found
No related tags found
1 merge request!1Create movement
Pipeline #206648 passed
assets/whiteball.png

496 B

......@@ -9,7 +9,7 @@ buildscript {
google()
}
dependencies {
classpath 'com.android.tools.build:gradle:7.4.2'
classpath 'com.android.tools.build:gradle:7.3.1'
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlinVersion"
classpath "com.adarshr:gradle-test-logger-plugin:3.2.0"
}
......
package tdt4240.netrunner
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.math.Vector2
class Move {
private var width: Int = Gdx.graphics.width
public var position: Vector2 = Vector2(width.toFloat()/2, 0f)
}
\ No newline at end of file
package tdt4240.netrunner
import com.badlogic.gdx.ApplicationAdapter
import com.badlogic.gdx.Game
import com.badlogic.gdx.Gdx
import com.badlogic.gdx.Input
import com.badlogic.gdx.graphics.Texture
import com.badlogic.gdx.graphics.g2d.SpriteBatch
import com.badlogic.gdx.math.Vector2
import com.badlogic.gdx.utils.ScreenUtils
import java.util.Vector
class Netrunner : ApplicationAdapter() {
var batch: SpriteBatch? = null
var img: Texture? = null
private lateinit var batch: SpriteBatch
private lateinit var img: Texture
private var position: Vector2 = Vector2(300f, 0f)
private var speed: Float = 10.0f;
override fun create() {
batch = SpriteBatch()
img = Texture("badlogic.jpg")
img = Texture("whiteball.png")
}
override fun render() {
ScreenUtils.clear(1f, 0f, 0f, 1f)
batch!!.begin()
batch!!.draw(img, 0f, 0f)
batch!!.end()
batch.begin()
batch.draw(img, position.x, position.y)
move(1.0f)
batch.end()
}
override fun dispose() {
batch!!.dispose()
img!!.dispose()
batch.dispose()
img.dispose()
}
fun move(dt: Float){
if (position.y == 0f){
position.y = 0f + img.height
}
if (position.y == Gdx.graphics.height.toFloat()){
position.y = Gdx.graphics.height.toFloat() - img.height
}
else {
if (Gdx.input.isKeyPressed(Input.Keys.DPAD_DOWN)) {
position.y -= dt * speed
}
if (Gdx.input.isKeyPressed(Input.Keys.DPAD_UP)) {
position.y += dt * speed
}
}
}
}
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment