import java.util.ArrayList; import java.awt.Color; public class Screen { public int[][] map; public int mapWidth, mapHeight, width, height; public ArrayList textures; public Screen(int[][] m, int mapW, int mapH, ArrayList tex, int w, int h) { map = m; mapWidth = mapW; mapHeight = mapH; textures = tex; width = w; height = h; } public int[] update(Camera camera, int[] pixels) { for(int n=0; n 0) hit = true; } //Calculate distance to the point of impact if(side==0) perpWallDist = Math.abs((mapX - camera.xPos + (1 - stepX) / 2) / rayDirX); else perpWallDist = Math.abs((mapY - camera.yPos + (1 - stepY) / 2) / rayDirY); //Now calculate the height of the wall based on the distance from the camera int lineHeight; if(perpWallDist > 0) lineHeight = Math.abs((int)(height / perpWallDist)); else lineHeight = height; //calculate lowest and highest pixel to fill in current stripe int drawStart = -lineHeight/2+ height/2; if(drawStart < 0) drawStart = 0; int drawEnd = lineHeight/2 + height/2; if(drawEnd >= height) drawEnd = height - 1; //add a texture int texNum = map[mapX][mapY] - 1; double wallX;//Exact position of where wall was hit if(side==1) {//If its a y-axis wall wallX = (camera.xPos + ((mapY - camera.yPos + (1 - stepY) / 2) / rayDirY) * rayDirX); } else {//X-axis wall wallX = (camera.yPos + ((mapX - camera.xPos + (1 - stepX) / 2) / rayDirX) * rayDirY); } wallX-=Math.floor(wallX); //x coordinate on the texture int texX = (int)(wallX * (textures.get(texNum).SIZE)); if(side == 0 && rayDirX > 0) texX = textures.get(texNum).SIZE - texX - 1; if(side == 1 && rayDirY < 0) texX = textures.get(texNum).SIZE - texX - 1; //calculate y coordinate on texture for(int y=drawStart; y>1) & 8355711;//Make y sides darker pixels[x + y*(width)] = color; } } return pixels; } }