Package game

Source Code of game.GameSystem

package game;

import game.finalTypes.Planet;
import game.finalTypes.Star;
import game.util.CollisionCheckEvent;
import game.util.GravityEvent;

import java.io.IOException;
import java.util.HashMap;

import math.Vector;

import org.newdawn.slick.opengl.Texture;
import org.newdawn.slick.opengl.TextureLoader;
import org.newdawn.slick.util.ResourceLoader;

public class GameSystem {

  Sector universe;
  Planet mercury, mercury2, earth;
  Star sun;
  HashMap<Object, Object> solvedCollisions = new HashMap<Object, Object>(4);

  public void init() throws IOException {
    mercury = new Planet(2000, 5000);
    mercury.setPosition(new Vector(-20000, 0, -40000));
    //mercury.setRotation(new Vector(0, 0.02f, 0));
    Texture texMercury = TextureLoader.getTexture("JPG",
        ResourceLoader.getResourceAsStream("res/mercury.jpg"));
    mercury.setTexture(texMercury);
   
    mercury2 = new Planet(2000, 5000);
    mercury2.setPosition(new Vector(0, -5000, -40000));
    //mercury2.setRotation(new Vector(0, 0.01f, 0));
    mercury2.setTexture(texMercury);
   
    earth = new Planet(3000, 5000);
    earth.setPosition(new Vector(10000, 0, -40000))
    //earth.setRotation(new Vector(0, -0.006f, 0));
    Texture texEarth = TextureLoader.getTexture("JPG",
        ResourceLoader.getResourceAsStream("res/earth.jpg"))
    earth.setTexture(texEarth);
   
    sun = new Star(7000, 500);
    sun.setPosition(new Vector(-30000, 20000, -40000))
    //sun.setRotation(new Vector(0, -0.006f, 0));
    Texture texSun = TextureLoader.getTexture("JPG",
        ResourceLoader.getResourceAsStream("res/sun.jpg"))
    sun.setTexture(texSun);

    universe = new Sector(null, new Vector(), new Vector(1e9f, 1e9f, 1e9f));
    universe.addObject(mercury);
    universe.addObject(mercury2);
    universe.addObject(earth);
    universe.addObject(sun);
   
    earth.applyImpulse(new Vector(0, 30e15f, 0), null);
    mercury.applyImpulse(new Vector(0, -30e15f, 0), null);
   
    earth.applyImpulse(new Vector(0, 1e20f, 0), new Vector(1, 0, 0));
   
    //earth.applyImpulse(new Vector(-1e16f, 0, 0), null);
    //mercury.applyImpulse(new Vector(3e16f, 0, 0), null);
  }

  public void render() { 
    universe.clearDynamics();
    universe.applyEvent(new GravityEvent(mercury));
    universe.applyEvent(new GravityEvent(earth));
    universe.applyEvent(new GravityEvent(mercury2))
    universe.applyEvent(new GravityEvent(sun));
   
    solvedCollisions.clear();
    universe.applyEvent(new CollisionCheckEvent(mercury, solvedCollisions));
    universe.applyEvent(new CollisionCheckEvent(earth, solvedCollisions))
    universe.applyEvent(new CollisionCheckEvent(mercury2, solvedCollisions));
    universe.applyEvent(new CollisionCheckEvent(sun, solvedCollisions));
   
    mercury.update(0.5f);
    earth.update(0.5f);
    mercury2.update(0.5f);
    sun.update(0.5f);
   
    mercury.render();
    earth.render();
    mercury2.render();
    sun.render();
  }

}
TOP

Related Classes of game.GameSystem

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.