/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package Tutorial3;

import jplay.GameImage;
import jplay.Keyboard;
import jplay.Physics;
import jplay.Sprite;
import jplay.Window;

/**
 * @author Leandro Emiliano Guimarães
 * ---UFF---
 * Computer Science
 */
public class Tutorial3 {
    public Tutorial3(){
        Window win = new Window(800,600);
        GameImage fundo = new GameImage("fundot1.png");
        Keyboard teclado = win.getKeyboard();


        Physics fisica = new Physics();
        fisica.createWorld(800, 600);


        Sprite quadrado = new Sprite("square.png");

        fisica.createBodyFromSprite(quadrado, false);

        quadrado.setX(200);
        quadrado.setY(0);

        quadrado.setBullet(true); // Evita que o sprite ignore a colisão com outro objeto.


        Sprite ground = new Sprite("ground.png");
        fisica.createBodyFromSprite(ground, true);

        ground.setY(500);
        ground.setFriction(0);

        Sprite spr = new Sprite("sprite.png");
        fisica.createBodyFromSprite(spr, true);

        spr.setX(100);
        spr.setY(200);

        Sprite boundX = new Sprite("limite.png");
        fisica.createBodyFromSprite(boundX, true);

        Sprite boundY = new Sprite("limite.png");
        fisica.createBodyFromSprite(boundY, true);

        boundY.setRotation(Math.PI/2);
        boundY.setX(-375);
        boundY.setY(300);

        Sprite boundY2 = new Sprite("limite.png");
        fisica.createBodyFromSprite(boundY2, true);

        boundY2.setRotation(Math.PI/2);
        boundY2.setX(375);
        boundY2.setY(300);

        
        while(true){

            fundo.draw();
            if(teclado.keyDown(Keyboard.RIGHT_KEY))
               quadrado.applyForceX(5000);

            if(teclado.keyDown(Keyboard.SPACE_KEY))
                quadrado.cancelForces();

            if(teclado.keyDown(Keyboard.LEFT_KEY))
                quadrado.applyForceX(-5000);

            fisica.update();
            win.update();
            win.delay(12);
        }

    }

    public static void main(String[] args) {
        Tutorial3 t3 = new Tutorial3();
    }
}
