Slick Forums

Discuss the Slick 2D Library
It is currently Wed Jun 19, 2013 1:11 pm

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
PostPosted: Fri Mar 30, 2012 4:51 pm 
Offline

Joined: Fri Mar 30, 2012 2:45 pm
Posts: 3
I've got this :
Code:
import org.jbox2d.common.Vec2;
import org.newdawn.fizzy.DynamicBody;
import org.newdawn.fizzy.Rectangle;
import org.newdawn.fizzy.StaticBody;
import org.newdawn.fizzy.World;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.Input;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;


public class GameplayState extends BasicGameState {
   private World world;
   private Rectangle floorShape;
   private StaticBody floorBody;
   
   
   private Rectangle manShape;
   private DynamicBody manBody;
   
   private Rectangle o1Shape;
   private DynamicBody o1Body;
   
   private Rectangle o2Shape;
   private DynamicBody o2Body;

   
   private Image podeaua;
   private Image om;
   private Image obs;
      
   private int dir = 1;
   
   private int stateID;
   
   SlickDebugDraw sDD;
   
   public GameplayState(int stateID) {
      this.stateID = stateID;
   }
   
   @Override
   public void init(GameContainer container, StateBasedGame game)
         throws SlickException {
      world = new World(new Vec2(0, 10));
      floorShape = new Rectangle(800, 30);
      floorBody = new StaticBody(floorShape, 0, 570);
      floorBody.setRestitution(0);
      
      manShape = new Rectangle(30,30);
      manBody = new DynamicBody(manShape, 400, 530);
      manBody.setRestitution(0);
      
      o1Shape = new Rectangle(30,30);
      o1Body = new DynamicBody(o1Shape, 350, 530);
      o1Body.setRestitution(0);
      
      o2Shape = new Rectangle(30,30);
      o2Body = new DynamicBody(o2Shape, 460, 530);
      o2Body.setRestitution(0);
      
      podeaua = new Image("data/podeaua.jpg");
      om = new Image("data/om.jpg");
      obs = new Image("data/obs.jpg");
      
      
      
      world.add(floorBody);
      world.add(manBody);
      world.add(o1Body);
      world.add(o2Body);
      
      
   }

   @Override
   public void render(GameContainer container, StateBasedGame game, Graphics g)
         throws SlickException {
      g.drawImage(podeaua,
            floorBody.getX(),
            floorBody.getY());
      
      g.drawImage(om,
            manBody.getX(),
            manBody.getY());
      
      g.drawImage(obs,
            o1Body.getX(),
            o1Body.getY());
            
      g.drawImage(obs,
            o2Body.getX(),
            o2Body.getY());
      
   }

   @Override
   public void update(GameContainer container, StateBasedGame game, int delta)
         throws SlickException {
      Input input = container.getInput();
      if(input.isKeyDown(Input.KEY_A)){
         manBody.setVelocity(-10, manBody.getYVelocity());
      } else if(input.isKeyDown(Input.KEY_D)){
         manBody.setVelocity(10, manBody.getYVelocity());
      } else {
         manBody.setVelocity(0, manBody.getYVelocity());
      }
      if(input.isKeyDown(Input.KEY_W) && manBody.isTouching(floorBody))
      {
         manBody.applyImpulse(0, -2000);
      }
      if(input.isMouseButtonDown(input.MOUSE_LEFT_BUTTON)) {
         manBody.setAngularVelocity(0);
         manBody.setRotation(0);
      }
      if(input.isMouseButtonDown(input.MOUSE_RIGHT_BUTTON)) {
         manBody.setAngularVelocity(+2f);
         
      }
      podeaua.setRotation((float) Math.toDegrees(floorBody.getRotation()));
      om.setRotation((float) Math.toDegrees(manBody.getRotation()));
      world.update(delta * 0.001f);
   }

   @Override
   public int getID() {
      // TODO Auto-generated method stub
      return stateID;
   }

}


When i rotate the main cube(manBody) using mouseButton2 the body starts acting crazy. I think i render this bad cuz i don't see what else would be the problem.

Here is the screen capture: http://youtu.be/Q5THJ54hHBw


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 1 post ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group