|
| 1 | +package Testing; |
| 2 | + |
| 3 | +import JavaGameEngine.Backend.ComponentHandler; |
| 4 | +import JavaGameEngine.Backend.Input.Input; |
| 5 | +import JavaGameEngine.Backend.Input.Keys; |
| 6 | +import JavaGameEngine.Backend.UpdateThread; |
| 7 | +import JavaGameEngine.Components.Collider.SquareCollider; |
| 8 | +import JavaGameEngine.Components.Component; |
| 9 | +import JavaGameEngine.Components.GameObject; |
| 10 | +import JavaGameEngine.Components.Physics.PhysicsBody; |
| 11 | +import JavaGameEngine.JavaGameEngine; |
| 12 | +import JavaGameEngine.msc.Vector2; |
| 13 | + |
| 14 | +import java.awt.*; |
| 15 | + |
| 16 | +public class Test extends JavaGameEngine { |
| 17 | + |
| 18 | + public static void main(String[] args){ |
| 19 | + init(); |
| 20 | + ComponentHandler.addObject(new Player()); |
| 21 | + GameObject g = new GameObject(); |
| 22 | + g.setScale(new Vector2(500,10)); |
| 23 | + g.addChild(new SquareCollider()); |
| 24 | + PhysicsBody b = new PhysicsBody(); |
| 25 | + g.setPosition(new Vector2(0,500)); |
| 26 | + b.setUseGravity(false); |
| 27 | + g.addChild(b); |
| 28 | + ComponentHandler.addObject(g); |
| 29 | + start(); |
| 30 | + } |
| 31 | + static class Player extends GameObject{ |
| 32 | + |
| 33 | + public Player(){ |
| 34 | + |
| 35 | + setColor(Color.CYAN); |
| 36 | + |
| 37 | + setTag("player"); |
| 38 | + PhysicsBody b = new PhysicsBody(); |
| 39 | + setPosition(new Vector2(400,300)); |
| 40 | + b.setUseGravity(true); |
| 41 | + addChild(b); |
| 42 | + SquareCollider s = new SquareCollider(); |
| 43 | + s.setVisible(true); |
| 44 | + addChild(s); |
| 45 | + } |
| 46 | + |
| 47 | + @Override |
| 48 | + public void update() { |
| 49 | + super.update(); |
| 50 | + if(Input.isKeyDown(Keys.D)){ |
| 51 | + movePosition(getPosition().add(Vector2.right)); |
| 52 | + } |
| 53 | + if(Input.isKeyDown(Keys.A)){ |
| 54 | + movePosition(getPosition().add(Vector2.left)); |
| 55 | + } |
| 56 | + if(Input.isKeyDown(Keys.W)){ |
| 57 | + movePosition(getPosition().add(Vector2.up)); |
| 58 | + } |
| 59 | + if(Input.isKeyDown(Keys.S)){ |
| 60 | + movePosition(getPosition().add(Vector2.down)); |
| 61 | + } |
| 62 | + //movePosition(Input.getMousePosition()); |
| 63 | + UpdateThread.camera.setPosition(getPosition().subtract(new Vector2(Test.GAMEWORLD.getWidth()/2,Test.GAMEWORLD.getHeight()/2))); |
| 64 | + } |
| 65 | + |
| 66 | + @Override |
| 67 | + public void draw(Graphics g) { |
| 68 | + super.draw(g); |
| 69 | + g.drawString(UpdateThread.camera.getPosition().toString(),50,50); |
| 70 | + g.drawString(getPosition().toString(),50,100); |
| 71 | + } |
| 72 | + } |
| 73 | + |
| 74 | +} |
0 commit comments