Skip to content

Commit

Permalink
Sprites are visible in every angle of player camera
Browse files Browse the repository at this point in the history
  • Loading branch information
Michał Podgajny committed Oct 15, 2022
1 parent 23e261f commit c7009af
Show file tree
Hide file tree
Showing 7 changed files with 44 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public final class ShapeHit {
private final static int min = 16;
private final static int max = 48;


public static boolean isInShape(){
boolean inX = PointOnRay.intdeltaPosX > min && PointOnRay.intdeltaPosX < max;
boolean inY = PointOnRay.intdeltaPosY > min && PointOnRay.intdeltaPosY < max;

return inX && inY;
}

public static void analyse(){
inX1 = (PointOnRay.intdeltaPosX == min && PointOnRay.lintdeltaPosX != min);
inX2 = (PointOnRay.intdeltaPosY == min && PointOnRay.lintdeltaPosY != min);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import com.example.raycaster.Model.Game.StartGame;
import com.example.raycaster.Model.Raycasting.GameLoop.RenderLoop;
import com.example.raycaster.Model.Raycasting.GameLoop.RenderLoopTask;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Sight;
import com.example.raycaster.Model.Raycasting.RenderProcedure;
import com.example.raycaster.R;
import com.example.raycaster.View.Render;
Expand All @@ -40,7 +41,7 @@ protected void onCreate(Bundle savedInstanceState) {

public void updateTextView(){
// update TextView here!
speedCounter.setText(RenderLoopTask.delay+" ms "+width+" "+height);
speedCounter.setText(RenderLoopTask.delay+" ms "+width+" "+height+ " angle:"+ RenderProcedure.angle);
}

public void startGame(View view){
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.raycaster.View.Raycasting.Blocks;

import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.ShapeHit;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.WallHit;
import com.example.raycaster.Model.Resources.Map.Map;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Ray;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Sight;
Expand All @@ -12,12 +14,6 @@

public final class Shpaes {

private static boolean isInShape(){
boolean inX = PointOnRay.intdeltaPosX > 16 && PointOnRay.intdeltaPosX < 48;
boolean inY = PointOnRay.intdeltaPosY > 16 && PointOnRay.intdeltaPosY < 48;

return inX && inY;
}

private static void ignoreBigDiffrence(int value){
int diff = value- Sight.lcolumn;
Expand Down Expand Up @@ -54,7 +50,7 @@ private static int countShadow(int value, int shadow){
}
public static void renderShapes(double r){

if(isInShape()) {
if(ShapeHit.isInShape()) {
Ray.finish = true;

final double height = PreColumn.height;
Expand All @@ -79,7 +75,7 @@ public static void renderShapes(double r){

Sight.wallinitized = true;

if(PointOnRay.lintdeltaPosX <=16 || PointOnRay.lintdeltaPosX>=48){
if(ShapeHit.inX1 ||ShapeHit.inX2){

ignoreBigDiffrence(PointOnRay.intdeltaPosY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.InPoint;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Ray;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Sight;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.ShapeHit;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PreColumns.PreColumn;
import com.example.raycaster.Model.Raycasting.Raycasting.RenderInfoBuffer;
Expand All @@ -11,14 +12,6 @@

public final class HalfShapes {

private static boolean inX;
private static boolean inY;

private static void detectShape(int intdeltaPosX,int intdeltaPosY){
inX = intdeltaPosX > 16 && intdeltaPosX < 48;
inY = intdeltaPosY > 16 && intdeltaPosY < 48;
}

private static int countShadowX(int intdeltaPosX,int shadow){
if (intdeltaPosX < 19) {
shadow = 1;
Expand Down Expand Up @@ -61,9 +54,7 @@ private static void renderWall(double height,int intdeltaPosX,int shadow,double

public static void renderHalfShapes(int intdeltaPosX,int intdeltaPosY){

detectShape(intdeltaPosX,intdeltaPosY);

if(inX && inY) {
if(ShapeHit.isInShape()) {
Ray.sprite = true;

final double height = PreColumn.height;
Expand All @@ -76,7 +67,7 @@ public static void renderHalfShapes(int intdeltaPosX,int intdeltaPosY){

if(lheight == 0) lheight = height;

if (PointOnRay.lintdeltaPosX <=16 || PointOnRay.lintdeltaPosX>=48) {
if (ShapeHit.inX1 ||ShapeHit.inX2) {

ignoreBigDiffrence(intdeltaPosY);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.InPoint;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Ray;
import com.example.raycaster.Model.Raycasting.Raycasting.Analyse.Entities.Sight;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PointOnRay;
import com.example.raycaster.Model.Raycasting.Raycasting.PreBaking.Ray.PreColumns.PreColumn;
import com.example.raycaster.Model.Raycasting.Raycasting.RenderInfoBuffer;
Expand All @@ -23,6 +24,7 @@ public final class SpriteRotateColumn extends SpriteRenderer{
private static double dtexX;



private static void prepare(double heights, double tex){
ys = RenderProcedure.cameraY - heights;
yf = RenderProcedure.cameraY + heights;
Expand Down Expand Up @@ -53,10 +55,29 @@ private static void prepare(double heights, double tex){
if (texX < 0) {
texX = 0;
}
if (PointOnRay.intdeltaPosX < 31 ) {
texX =(127 - texX);
}

if((RenderProcedure.angle<0 && RenderProcedure.angle>-RenderProcedure.pi) ||
(RenderProcedure.angle<2*RenderProcedure.pi && RenderProcedure.angle>RenderProcedure.pi)) {
if (Sight.tan > 0) {
if (PointOnRay.intdeltaPosX < 32) {
texX = (127 - texX);
}
} else {
if (PointOnRay.intdeltaPosX >= 32) {
texX = (127 - texX);
}
}
}else{
if (Sight.tan < 0) {
if (PointOnRay.intdeltaPosX < 32) {
texX = (127 - texX);
}
} else {
if (PointOnRay.intdeltaPosX >= 32) {
texX = (127 - texX);
}
}
}

}
dtexX = (texX - ltexX) / (double) RenderProcedure.SCREEN_STEP;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@

public final class UpperShapes{

private static boolean isInShape(){
boolean inX = PointOnRay.intdeltaPosX > 16 && PointOnRay.intdeltaPosX < 48;
boolean inY = PointOnRay.intdeltaPosY > 16 && PointOnRay.intdeltaPosY < 48;

return inX && inY;
}

private static void renderYWall(double height,double lha){
Column.drawLine((short) (Sight.posScreenX - RenderProcedure.D_SCREEN_STEP), (int) height, (int) lha, PointOnRay.intdeltaPosY, RenderInfoBuffer.lcolumnh[InPoint.countPos],
0, Ray.half, true, PreColumn.llminh, PreColumn.llmaxh, false, 0, false, false);
Expand All @@ -32,15 +25,15 @@ private static void renderXWall(double height,double lha){
}
public static void renderUpperShapes(){

if (isInShape()) {
if (ShapeHit.isInShape()) {

ShapeHit.analyse();
if (Sight.renderwall && !Ray.luppershape) {

final double height = PreColumn.fakeHeight/PreColumn.z;
double lha = PreColumn.getLastUpperHeight(height);

if( PointOnRay.lintdeltaPosX <=16 || PointOnRay.lintdeltaPosX>=48){
if( ShapeHit.inX1 ||ShapeHit.inX2){

renderYWall(height,lha);
RenderInfoBuffer.lcolumnh[InPoint.countPos] = PointOnRay.intdeltaPosY;
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/activity_main.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
android:rotation="0"
android:text="TextView"
android:textColor="@android:color/holo_red_dark"
android:visibility="invisible"
android:visibility="visible"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />

Expand Down

0 comments on commit c7009af

Please sign in to comment.