Fixed weird collision checking
Co-authored-by: r3cp3ct <45179536+r3cp3ct@users.noreply.github.com> Co-authored-by: sigonasr2 <sigonasr2@gmail.com>
This commit is contained in:
parent
5e71aee562
commit
227468b474
@ -1,9 +1,9 @@
|
|||||||
build2.sh
|
|
||||||
build.sh
|
build.sh
|
||||||
|
build2.sh
|
||||||
clean.sh
|
clean.sh
|
||||||
commit.sh
|
commit.sh
|
||||||
jar2.sh
|
|
||||||
jar.sh
|
jar.sh
|
||||||
|
jar2.sh
|
||||||
release.sh
|
release.sh
|
||||||
update.sh
|
update.sh
|
||||||
version_info
|
version_info
|
||||||
|
@ -1,9 +1,9 @@
|
|||||||
build2.sh:b1c6b7c6b2eb19ba54be6824bda8805b -
|
build.sh:5df470d49036bf7565493739aeebeaa8 *-
|
||||||
build.sh:5df470d49036bf7565493739aeebeaa8 -
|
build2.sh:b1c6b7c6b2eb19ba54be6824bda8805b *-
|
||||||
clean.sh:668a2f9b568c55f6a044a509315032f6 -
|
clean.sh:668a2f9b568c55f6a044a509315032f6 *-
|
||||||
commit.sh:5e4448db9ad48e72ec3a1ff4f5763b41 -
|
commit.sh:5e4448db9ad48e72ec3a1ff4f5763b41 *-
|
||||||
jar2.sh:7977fc138ee5db798d08c34734f0be93 -
|
jar.sh:821d5a109324d405f05c35c4bb129375 *-
|
||||||
jar.sh:821d5a109324d405f05c35c4bb129375 -
|
jar2.sh:7977fc138ee5db798d08c34734f0be93 *-
|
||||||
release.sh:027178aa6da76180401a188d8f03af64 -
|
release.sh:027178aa6da76180401a188d8f03af64 *-
|
||||||
update.sh:3be721658983183efa395984acd96b03 -
|
update.sh:3be721658983183efa395984acd96b03 *-
|
||||||
zip.sh:273f5a83b80a8e54022d60514dfeec0a -
|
zip.sh:273f5a83b80a8e54022d60514dfeec0a *-
|
||||||
|
BIN
maps/world1.map
BIN
maps/world1.map
Binary file not shown.
2
sig
2
sig
@ -1,4 +1,4 @@
|
|||||||
export AUTO_UPDATE=true
|
export AUTO_UPDATE=false
|
||||||
|
|
||||||
source utils/define.sh
|
source utils/define.sh
|
||||||
|
|
||||||
|
@ -39,7 +39,7 @@ public class Erinoah extends PhysicsObject implements RenderedObject{
|
|||||||
@Override
|
@Override
|
||||||
public void update(double updateMult) {
|
public void update(double updateMult) {
|
||||||
super.update(updateMult);
|
super.update(updateMult);
|
||||||
/*lastMoved+=updateMult;
|
lastMoved+=updateMult;
|
||||||
lastJumped+=updateMult;
|
lastJumped+=updateMult;
|
||||||
if (lastMoved>5) {
|
if (lastMoved>5) {
|
||||||
switch ((int)(Math.random()*3)) {
|
switch ((int)(Math.random()*3)) {
|
||||||
@ -64,7 +64,7 @@ public class Erinoah extends PhysicsObject implements RenderedObject{
|
|||||||
lastJumped=0;
|
lastJumped=0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
moveTimer-=updateMult;*/
|
moveTimer-=updateMult;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -52,7 +52,7 @@ public class Player extends PhysicsObject{
|
|||||||
setVelocityLimits(246, 500);
|
setVelocityLimits(246, 500);
|
||||||
setGroundDrag(2000);
|
setGroundDrag(2000);
|
||||||
setGroundFriction(PhysicsObject.NORMAL_FRICTION);
|
setGroundFriction(PhysicsObject.NORMAL_FRICTION);
|
||||||
setAirDrag(800);
|
setAirDrag(1000);
|
||||||
setAirFriction(180);
|
setAirFriction(180);
|
||||||
setSlidingVelocity(164);
|
setSlidingVelocity(164);
|
||||||
setSlidingAcceleration(120);
|
setSlidingAcceleration(120);
|
||||||
@ -61,7 +61,7 @@ public class Player extends PhysicsObject{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Rectangle setCollisionBounds() {
|
public Rectangle setCollisionBounds() {
|
||||||
return new Rectangle(10,2,12,27);
|
return new Rectangle(10,6,12,25);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -1,6 +1,7 @@
|
|||||||
package sig.objects.actor;
|
package sig.objects.actor;
|
||||||
|
|
||||||
import sig.RabiClone;
|
import sig.RabiClone;
|
||||||
|
import sig.engine.Action;
|
||||||
import sig.engine.AnimatedSprite;
|
import sig.engine.AnimatedSprite;
|
||||||
import sig.engine.Panel;
|
import sig.engine.Panel;
|
||||||
import sig.engine.Rectangle;
|
import sig.engine.Rectangle;
|
||||||
@ -22,7 +23,6 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
|
|||||||
protected byte maxJumpCount=2;
|
protected byte maxJumpCount=2;
|
||||||
protected byte jumpCount=0;
|
protected byte jumpCount=0;
|
||||||
protected double jump_velocity;
|
protected double jump_velocity;
|
||||||
|
|
||||||
protected double horizontal_air_friction,horizontal_air_drag;
|
protected double horizontal_air_friction,horizontal_air_drag;
|
||||||
protected double horizontal_friction,horizontal_drag;
|
protected double horizontal_friction,horizontal_drag;
|
||||||
protected double sliding_velocity,sliding_acceleration;
|
protected double sliding_velocity,sliding_acceleration;
|
||||||
@ -58,6 +58,9 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
|
|||||||
|
|
||||||
boolean sideCollision = false;
|
boolean sideCollision = false;
|
||||||
boolean hitAbove=false;
|
boolean hitAbove=false;
|
||||||
|
|
||||||
|
double startingX=getX();
|
||||||
|
|
||||||
if (y_velocity==0) {
|
if (y_velocity==0) {
|
||||||
if (!(checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX2(),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2)||
|
if (!(checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX2(),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2)||
|
||||||
checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX(),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2))) {
|
checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX(),getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2))) {
|
||||||
@ -69,12 +72,13 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
|
|||||||
} else {
|
} else {
|
||||||
double startingY=getY();
|
double startingY=getY();
|
||||||
groundCollision=false;
|
groundCollision=false;
|
||||||
|
|
||||||
if (displacement_y>0) {
|
if (displacement_y>0) {
|
||||||
for (int y=(int)getY();y<startingY+displacement_y;y++) {
|
for (int y=(int)getY();y<startingY+displacement_y;y++) {
|
||||||
if (y==getY()) {
|
if (y==getY()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX2()-1,y+getCollisionBox().getY2()-getSprite().getHeight()/2)||
|
if (checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX2(),y+getCollisionBox().getY2()-getSprite().getHeight()/2)||
|
||||||
checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX()+1,y+getCollisionBox().getY2()-getSprite().getHeight()/2)) {
|
checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX()+1,y+getCollisionBox().getY2()-getSprite().getHeight()/2)) {
|
||||||
setY(y-0.1);
|
setY(y-0.1);
|
||||||
//System.out.println("Running"+System.currentTimeMillis());
|
//System.out.println("Running"+System.currentTimeMillis());
|
||||||
@ -92,7 +96,7 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
|
|||||||
if (y==getY()) {
|
if (y==getY()) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX2()-1,y+getCollisionBox().getY()-getSprite().getHeight()/2)||
|
if (checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX2(),y+getCollisionBox().getY()-getSprite().getHeight()/2)||
|
||||||
checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX()+1,y+getCollisionBox().getY()-getSprite().getHeight()/2)) {
|
checkCollision(getX()-getSprite().getWidth()/2+getCollisionBox().getX()+1,y+getCollisionBox().getY()-getSprite().getHeight()/2)) {
|
||||||
setY(y+1);
|
setY(y+1);
|
||||||
hitAbove=true;
|
hitAbove=true;
|
||||||
@ -106,8 +110,29 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
sideCollision = sideCollisionChecking(displacement_x, sideCollision, hitAbove, startingX);
|
||||||
|
|
||||||
double startingX=getX();
|
|
||||||
|
if (!groundCollision){
|
||||||
|
this.setY(this.getY()+displacement_y);
|
||||||
|
y_acceleration = GRAVITY;
|
||||||
|
if(y_velocity>0 && state!=State.SLIDE){
|
||||||
|
state = State.FALLING;
|
||||||
|
}
|
||||||
|
if (!sideCollision) {
|
||||||
|
handleKeyboardMovement(updateMult, right-left, horizontal_air_friction, horizontal_air_drag);
|
||||||
|
this.setX(this.getX()+displacement_x);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
if (!sideCollision) {
|
||||||
|
handleKeyboardMovement(updateMult, right-left, horizontal_friction, horizontal_drag);
|
||||||
|
this.setX(this.getX()+displacement_x);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private boolean sideCollisionChecking(double displacement_x, boolean sideCollision, boolean hitAbove, double startingX) {
|
||||||
if (displacement_x>0.00001) {
|
if (displacement_x>0.00001) {
|
||||||
for (int x=(int)getX();x<startingX+displacement_x;x++) {
|
for (int x=(int)getX();x<startingX+displacement_x;x++) {
|
||||||
if (x==getX()) {
|
if (x==getX()) {
|
||||||
@ -157,27 +182,12 @@ public abstract class PhysicsObject extends AnimatedObject implements PhysicsObj
|
|||||||
checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2))) {
|
checkCollision(x+getCollisionBox().getX2()-getSprite().getWidth()/2,(getY()-getSprite().getHeight()/2+getCollisionBounds().getY2()+2))) {
|
||||||
//System.out.println("Performs check."+System.currentTimeMillis());
|
//System.out.println("Performs check."+System.currentTimeMillis());
|
||||||
setY(getY()+1);
|
setY(getY()+1);
|
||||||
//x_velocity = ;
|
//x_velocity =;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (!groundCollision){
|
return sideCollision;
|
||||||
this.setY(this.getY()+displacement_y);
|
|
||||||
y_acceleration = GRAVITY;
|
|
||||||
if(y_velocity>0 && state!=State.SLIDE){
|
|
||||||
state = State.FALLING;
|
|
||||||
}
|
|
||||||
if (!sideCollision) {
|
|
||||||
handleKeyboardMovement(updateMult, right-left, horizontal_air_friction, horizontal_air_drag);
|
|
||||||
this.setX(this.getX()+displacement_x);
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
if (!sideCollision) {
|
|
||||||
handleKeyboardMovement(updateMult, right-left, horizontal_friction, horizontal_drag);
|
|
||||||
this.setX(this.getX()+displacement_x);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected boolean checkCollision(double x,double y) {
|
protected boolean checkCollision(double x,double y) {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
.coauthors
|
.coauthors
|
||||||
|
.updateDirectories
|
||||||
define.sh
|
define.sh
|
||||||
main.sh
|
main.sh
|
||||||
search.sh
|
search.sh
|
||||||
.updateDirectories
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
define.sh:3ecab0dffe2adfb950f3eb7c7061b750 -
|
.updateDirectories:0ede00461e947494545e694040787b3f *-
|
||||||
main.sh:d3d1bd0b56d8114eb7479964227f8576 -
|
define.sh:3ecab0dffe2adfb950f3eb7c7061b750 *-
|
||||||
search.sh:81d08f5ff48e8a44b5f68387d426da05 -
|
main.sh:d3d1bd0b56d8114eb7479964227f8576 *-
|
||||||
.updateDirectories:0ede00461e947494545e694040787b3f -
|
search.sh:81d08f5ff48e8a44b5f68387d426da05 *-
|
||||||
|
Loading…
x
Reference in New Issue
Block a user