Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 1 of 1

Thread: Small problem in big code, not sure why

  1. #1
    Junior Member
    Join Date
    Oct 2011
    Thanked 0 Times in 0 Posts

    Default Small problem in big code, not sure why

    Hi everyone!

    I've been following Notches livestream of creating "Prelude Of The Chambered"

    First off let me explain why i'm doing this.

    Im only 16 and there's no programming courses available for me to take atm.
    So the way i learn is by reading professionals code. or going through with a livestream.

    Now the problem
    (For those of you who watched) i'm at the point where wall collisions are made.
    for some reason, it wont let me past the fourth level block facing forward, and doesn't collide with any blocks facing forward.

    I've tried everything, the code is EXACTLY the same (i'm 99% sure) and the code for the final version he added for download is a changed version. which is VERY different.

    i've narrowed it down to somewhere here:
    package com.diesal11.escape.entities;
    import com.diesal11.escape.level.Level;
    public class Player {
    	public double x, z, rot;
    	public double xa, za, rota;
    	public Level level;
    	public Player(Level level) {
    		this.level = level;
    	public void tick(boolean up, boolean down, boolean left, boolean right, boolean turnLeft, boolean turnRight) {
    		double rotSpeed = 0.05;
    		double walkSpeed = 0.05;
    		if (turnLeft)
    			rota -= rotSpeed;
    		if (turnRight)
    			rota += rotSpeed;
    		double xm = 0;
    		double zm = 0;
    		if (up)
    		if (down)
    		if (left)
    		if (right)
    		xa += (xm * Math.cos(rot) + zm * Math.sin(rot)) * walkSpeed;
    		if (isFree(x + xa, z)) {
    			x += xa;
    		za += (zm * Math.cos(rot) - xm * Math.sin(rot)) * walkSpeed;
    		if (isFree(xa, z + za)) {
    			z += za;
    		xa *= 0.2;
    		za *= 0.2;
    		rot += rota;
    		rota *= 0.2;
    	private boolean isFree(double xx, double yy) {
    		double r = 0.25;
    		int x0 = (int) Math.floor(xx + 0.5 - r);
    		int x1 = (int) Math.floor(xx + 0.5 + r);
    		int y0 = (int) Math.floor(yy + 0.5 - r);
    		int y1 = (int) Math.floor(yy + 0.5 + r);
    		if (level.getBlock(x0, y0).blocksMotion) return false;
    		if (level.getBlock(x1, y0).blocksMotion) return false;
    		if (level.getBlock(x0, y1).blocksMotion) return false;
    		if (level.getBlock(x1, y1).blocksMotion) return false;
    		return true;

    		Level level = game.level;
    		int r = 6;
    		int xCenter = (int) (Math.floor(xCam));
    		int zCenter = (int) (Math.floor(yCam));
    		for (int zb = zCenter - r; zb <= zCenter + r; zb++) {
    			for (int xb = xCenter - r; xb <= xCenter + r; xb++) {
    				Block c = level.getBlock(xb, zb);
    				Block e = level.getBlock(xb + 1, zb);
    				Block s = level.getBlock(xb, zb + 1);
    				if (c.solidRender) {
    					if (!e.solidRender) {
    						renderWall(xb + 1, zb, xb + 1, zb + 1);
    					if (!s.solidRender) {
    						renderWall(xb + 1, zb + 1, xb, zb + 1);
    				} else {
    					if (e.solidRender) {
    						renderWall(xb + 1, zb + 1, xb + 1, zb);
    					if (s.solidRender) {
    						renderWall(xb, zb + 1, xb + 1, zb + 1);

    I've also added the current code in at as an attachment so you can compile yourself.


    Thanks a lot in advance, I've tried for ages to fix this myself but i can't figure it out!

    Any Questions just ask!
    Last edited by diesal11; October 16th, 2011 at 11:52 AM. Reason: Numerous Typos

Similar Threads

  1. [SOLVED] Small problem regarding inheritance of classes
    By Stockholm Syndrome in forum What's Wrong With My Code?
    Replies: 9
    Last Post: October 10th, 2011, 02:11 PM
  2. Small problem, help please?
    By Jonathansafc in forum What's Wrong With My Code?
    Replies: 33
    Last Post: September 3rd, 2011, 06:46 PM
  3. WatchService - small code for monitoring folders
    By zincc in forum What's Wrong With My Code?
    Replies: 5
    Last Post: March 8th, 2011, 10:19 AM
  4. keylistener small problem
    By matecno in forum What's Wrong With My Code?
    Replies: 4
    Last Post: November 14th, 2010, 08:51 PM
  5. small problem ... I need help
    By Ashar in forum Loops & Control Statements
    Replies: 4
    Last Post: December 4th, 2009, 11:26 AM