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:
Player.Java
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) zm++; if (down) zm--; if (left) xm--; if (right) xm++; 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; } }
Bitmap3D.java:
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.
Escape.rar
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!