Skip to content

Commit

Permalink
fix(collision): fixed collision implementation post using world coord…
Browse files Browse the repository at this point in the history
…inates, Status: Working
  • Loading branch information
sanjeev309 committed Jan 10, 2019
1 parent 5af4769 commit 2097f15
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@
import com.badlogic.gdx.math.Rectangle;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.Array;
import com.studio.sanjeev.storklight.StorkLightGameClass;

import java.util.Random;

/**
Expand All @@ -18,8 +20,9 @@

public class CollectibleOrbs {
private static final int ORB_COUNT = 10;
private static final int DARK_COUNT = 15;
private static final int ORB_RADIUS = 22;
private static final int DARK_COUNT = 10;
private static final int ORB_RADIUS = 1;
private static final int ORB_SPEED = 14;
private Array<Orb> orbs;
private Array<Dark> darks;
private Orb orb;
Expand All @@ -34,7 +37,7 @@ public CollectibleOrbs(OrthographicCamera cam){
column = new Array<Integer>();
shapeRenderer = new ShapeRenderer();
shapeRenderer.setProjectionMatrix(cam.combined);
int step = Gdx.graphics.getHeight()/NumSteps;
int step = 100/NumSteps;

for(int i = step; i< (step*NumSteps) ; i = i + step){
column.add(i);
Expand Down Expand Up @@ -65,11 +68,11 @@ public void render(SpriteBatch sb){
// shapeRenderer.setColor(Color.RED);

for(Orb orb:orbs){
sb.draw(orb.getOrbTexture(),orb.position.x,orb.position.y);
sb.draw(orb.getOrbTexture(),orb.position.x,orb.position.y,4,4);
// shapeRenderer.circle(orb.position.x,orb.position.y,5);
}
for(Dark dark : darks){
sb.draw(dark.getDarkTexture(),dark.position.x,dark.position.y);
sb.draw(dark.getDarkTexture(),dark.position.x,dark.position.y,4,4);
// shapeRenderer.circle(dark.position.x,dark.position.y,5);
}
// shapeRenderer.end();
Expand All @@ -83,7 +86,7 @@ public int checkCollision(Rectangle stork){
int ret=0;
for(Orb orb: orbs){
if(stork.contains(orb.getOrbCircle())){
orb.reposition();
orb.reposition();
ret= 1;
}
}
Expand All @@ -107,7 +110,7 @@ private class Orb{

public Orb(){
rand = new Random();
position = new Vector2(rand.nextInt(Gdx.graphics.getWidth()) +Gdx.graphics.getWidth(),rand.nextInt(Gdx.graphics.getHeight()));
position = new Vector2(rand.nextInt(StorkLightGameClass.WIDTH) + StorkLightGameClass.WIDTH,rand.nextInt(StorkLightGameClass.HEIGHT));
orbCircle = new Circle(position.x,position.y,ORB_RADIUS);
orbCircle.setPosition(position);
texture = new Texture(Gdx.files.internal("particle/orbSprite.png"));
Expand All @@ -120,12 +123,12 @@ public Texture getOrbTexture(){

public void update(float dt){
if(position.x< -32){
position.x = rand.nextInt(Gdx.graphics.getWidth()) + Gdx.graphics.getWidth();
position.x = rand.nextInt(StorkLightGameClass.WIDTH) + StorkLightGameClass.WIDTH;
position.y = column.get(rand.nextInt(NumSteps - 1));
}
else
{
position.x-= 150*dt;
position.x-= ORB_SPEED*dt;
}
orbCircle.set(position.x,position.y,ORB_RADIUS);
}
Expand All @@ -135,7 +138,7 @@ public void dispose(){
public Circle getOrbCircle(){return orbCircle;}

public void reposition(){
position.x = rand.nextInt(Gdx.graphics.getWidth()) + Gdx.graphics.getWidth();
position.x = rand.nextInt(100) + 100;
position.y = column.get(rand.nextInt(NumSteps - 1));
}
}
Expand All @@ -147,20 +150,20 @@ private class Dark{
private Circle darkCircle;
public Dark(){
rand = new Random();
position = new Vector2(rand.nextInt(Gdx.graphics.getWidth()) + Gdx.graphics.getWidth(),rand.nextInt(Gdx.graphics.getHeight()));
position = new Vector2(rand.nextInt(StorkLightGameClass.WIDTH) + StorkLightGameClass.WIDTH,rand.nextInt(StorkLightGameClass.HEIGHT));
darkCircle = new Circle(position.x,position.y,ORB_RADIUS);
texture = new Texture(Gdx.files.internal("particle/darkSprite.png"));
}


public void update(float dt){
if(position.x< -32){
position.x = rand.nextInt(Gdx.graphics.getWidth()) + Gdx.graphics.getWidth();
position.x = rand.nextInt(StorkLightGameClass.WIDTH) + StorkLightGameClass.WIDTH;
position.y = column.get(rand.nextInt(NumSteps - 1));
}
else
{
position.x-= 150*dt;
position.x-= ORB_SPEED*dt;
}
darkCircle.set(position.x,position.y,ORB_RADIUS);
}
Expand All @@ -171,7 +174,7 @@ public void dispose(){
public Circle getDarkCircle(){return darkCircle;}

public void reposition(){
position.x = rand.nextInt(Gdx.graphics.getWidth()) + Gdx.graphics.getWidth();
position.x = rand.nextInt(StorkLightGameClass.WIDTH) + 100;
position.y = column.get(rand.nextInt(NumSteps - 1));
}
}
Expand Down
15 changes: 9 additions & 6 deletions core/src/com/studio/sanjeev/storklight/sprites/Stork.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
public class Stork {
private static final int GRAVITY = -10;
private static final int MOVEMENT = 0;
private static final int WIDTH = 10;
private static final int HEIGHT = 10;
private static final int STORK_SPEED = 18;

private Vector3 position;
private Vector3 velocity;
private Animation storkAnimation;
Expand All @@ -30,9 +34,8 @@ public Stork(int x, int y){
position = new Vector3(x,y,0);
velocity = new Vector3(0,0,0);
Texture texture = new Texture("storkanim.png");
storkRectangle = new Rectangle(x,y,texture.getWidth(),texture.getHeight());
storkAnimation = new Animation( texture, 6, 0.3f);
storkRectangle = new Rectangle(x,y,getTextureRegion().getRegionWidth(),getTextureRegion().getRegionHeight());
storkRectangle = new Rectangle(x,y,WIDTH,HEIGHT);
}
public void update(float dt){

Expand All @@ -49,15 +52,15 @@ public void update(float dt){
position.y = 0;
}

if(position.y > 100 - storkAnimation.getTextureRegion().getRegionHeight()/2){
position.y = 100 - storkAnimation.getTextureRegion().getRegionHeight()/2;
if(position.y > 95 ){
position.y = 95 ;
velocity.y = 0;
}

storkRectangle = new Rectangle(position.x ,position.y,storkAnimation.getTextureRegion().getRegionWidth(),storkAnimation.getTextureRegion().getRegionHeight());
storkRectangle = new Rectangle(position.x ,position.y,WIDTH,HEIGHT);
}
public void fly(){
velocity.y = velocity.y + 20;
velocity.y = velocity.y + STORK_SPEED;
}

public Rectangle getBoundingRectangle(){
Expand Down

0 comments on commit 2097f15

Please sign in to comment.