From 56c5695267c5d9900d422b195e87feb96631db4f Mon Sep 17 00:00:00 2001 From: Marcus Gosselin Date: Tue, 16 Feb 2016 04:48:15 -0500 Subject: [PATCH] player controller --- bin/.gitignore | 1 + bin/Space Wars/game.scene | 47 ++++++++++++++++++++++++++--- src/Space Wars/game.scene | 47 ++++++++++++++++++++++++++--- src/spacewars/PlayerController.java | 22 ++++++++++++++ 4 files changed, 109 insertions(+), 8 deletions(-) diff --git a/bin/.gitignore b/bin/.gitignore index 3d120a3..0c53e5e 100644 --- a/bin/.gitignore +++ b/bin/.gitignore @@ -1 +1,2 @@ /spacewars/ +/Space Wars/ diff --git a/bin/Space Wars/game.scene b/bin/Space Wars/game.scene index ced3375..134522b 100644 --- a/bin/Space Wars/game.scene +++ b/bin/Space Wars/game.scene @@ -1,3 +1,14 @@ +[diveengine2d.Entity] +$GUID = "9e477f6d-778d-43e2-afe0-028a0a99cd74" +$name = "background" + +Component RectRenderer +$name = "render!" +$width = 1024i +$height = 600i +$color = #f0f0f0 +End Component + [diveengine2d.Entity] $GUID = "9e477f6d-778d-43e2-afe0-028a0a99cd74" $name = "Player" @@ -5,11 +16,39 @@ $name = "Player" Component spacewars.PlayerController $name = "player controller" $message = "hello from the script!" +$speed = 2i End Component Component RectRenderer $name = "render!" -$width = 16F -$height = 16F -$color = #776611 -End Component \ No newline at end of file +$width = 16i +$height = 16i +$color = #05FABB +End Component + +Component RigidBody +$name = "poop" +$friction = .9F +End Component + +[diveengine2d.Entity] +$GUID = "9e477f6d-778d-43e2-afe0-028a0a99cd74" +$name = "Player" + +Component spacewars.PlayerController +$name = "player controller" +$message = "hello from the script!" +$speed = 1f +End Component + +Component RectRenderer +$name = "render!" +$width = 16i +$height = 16i +$color = #FA05BB +End Component + +Component RigidBody +$name = "poop" +$friction = .9F +End Component diff --git a/src/Space Wars/game.scene b/src/Space Wars/game.scene index ced3375..134522b 100644 --- a/src/Space Wars/game.scene +++ b/src/Space Wars/game.scene @@ -1,3 +1,14 @@ +[diveengine2d.Entity] +$GUID = "9e477f6d-778d-43e2-afe0-028a0a99cd74" +$name = "background" + +Component RectRenderer +$name = "render!" +$width = 1024i +$height = 600i +$color = #f0f0f0 +End Component + [diveengine2d.Entity] $GUID = "9e477f6d-778d-43e2-afe0-028a0a99cd74" $name = "Player" @@ -5,11 +16,39 @@ $name = "Player" Component spacewars.PlayerController $name = "player controller" $message = "hello from the script!" +$speed = 2i End Component Component RectRenderer $name = "render!" -$width = 16F -$height = 16F -$color = #776611 -End Component \ No newline at end of file +$width = 16i +$height = 16i +$color = #05FABB +End Component + +Component RigidBody +$name = "poop" +$friction = .9F +End Component + +[diveengine2d.Entity] +$GUID = "9e477f6d-778d-43e2-afe0-028a0a99cd74" +$name = "Player" + +Component spacewars.PlayerController +$name = "player controller" +$message = "hello from the script!" +$speed = 1f +End Component + +Component RectRenderer +$name = "render!" +$width = 16i +$height = 16i +$color = #FA05BB +End Component + +Component RigidBody +$name = "poop" +$friction = .9F +End Component diff --git a/src/spacewars/PlayerController.java b/src/spacewars/PlayerController.java index 0ea4bbf..73c23bf 100644 --- a/src/spacewars/PlayerController.java +++ b/src/spacewars/PlayerController.java @@ -1,7 +1,29 @@ package spacewars; +import java.awt.event.KeyEvent; + import diveengine2d.DiveScript; +import diveengine2d.Input; +import diveengine2d.RigidBody; public class PlayerController extends DiveScript { public String message = null; + public float speed; + + private RigidBody rigidBody; + + public void create() { + rigidBody = (RigidBody) entity.components.get(2); + } + + public void update() { + if(Input.getKeyDown(KeyEvent.VK_W)) + rigidBody.dy += -1 * speed; + if(Input.getKeyDown(KeyEvent.VK_S)) + rigidBody.dy += 1 * speed; + if(Input.getKeyDown(KeyEvent.VK_A)) + rigidBody.dx += -1 * speed; + if(Input.getKeyDown(KeyEvent.VK_D)) + rigidBody.dx += 1 * speed; + } }