Slick Forums

Discuss the Slick 2D Library
It is currently Wed Oct 17, 2018 1:32 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Boxes cutting corners
PostPosted: Mon Oct 29, 2012 5:31 pm 
Offline

Joined: Mon Oct 29, 2012 5:25 pm
Posts: 3
Hello,
I'm using Slick and Phys2d to make a 2D platforming game. I'm using Phys2d bodies and Slick images in tandem to create entities, platforms, etc. My problem is, it seems like the bodies are cutting corners. This is especially an issue with gravity, because the player seems to slide off the edge of the platform if he gets too close. Consider this screenshot:
Image
This is the source code:
Code:
import org.newdawn.slick.*;
import net.phys2d.raw.*;
import net.phys2d.raw.shapes.*;
import net.phys2d.math.*;

public class MainTest extends BasicGame
{
   Image box1, box2;
   Body body1, body2;
   World world;
   
   public MainTest()
   {
      super("SlickForumsTest");
   }
   
    public void init(GameContainer gc)
   {
       try {
          box1 = new Image("img/box1.png");
          box2 = new Image("img/box2.png");
       }
       catch(SlickException e) {
          e.printStackTrace();
       }
       body1 = new Body(new Box(40, 40), 100);
       body2 = new StaticBody(new Box(200, 40));
       body1.setPosition(100, 100);
       body2.setPosition(200, 200);
       
       world = new World(new Vector2f(0, 0), 100);
       world.add(body1);
       world.add(body2);
    }
 
    @Override
    public void update(GameContainer gc, int delta)
    {
       world.step();
       
       if(gc.getInput().isKeyDown(Input.KEY_LEFT))
          body1.adjustPosition(new Vector2f(-0.25f * delta, 0));
       if(gc.getInput().isKeyDown(Input.KEY_RIGHT))
          body1.adjustPosition(new Vector2f(0.25f * delta, 0));
       if(gc.getInput().isKeyDown(Input.KEY_UP))
          body1.adjustPosition(new Vector2f(0, -0.25f * delta));
       if(gc.getInput().isKeyDown(Input.KEY_DOWN))
          body1.adjustPosition(new Vector2f(0, 0.25f * delta));
    }
 
    public void render(GameContainer gc, Graphics g)
          throws SlickException
    {
       box1.draw(body1.getPosition().getX() - 20, body1.getPosition().getY() - 20);
       box2.draw(body2.getPosition().getX() - 100, body2.getPosition().getY() - 20);
    }
   
    public static void main(String[] args) throws SlickException
    {
       AppGameContainer app =
         new AppGameContainer(new MainTest());

       app.setDisplayMode(800, 600, false);
       app.start();
    }
}

Is there a way to stop these boxes from cutting corners?


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:  
cron
Powered by phpBB® Forum Software © phpBB Group