I am trying to build this game where the player hops between a number of ropes.
For now, in addition to my main activity that I kept empty, I built two additional classes:
Ropes.java
, storing the coordinates of the ropes and their movementPlayer.java
, storing the player's details
Can you advise me about the next step to join them? For instance, where to include the "attach function" that links the player to the rope in case he reaches it?
And how would I populate the main activity to organize the game?
To further explain my problem, I will join my three activities below: the first is the rope class; the second is player class:
Rope class:
import android.content.Context;
import android.graphics.Canvas;
import android.graphics.drawable.Drawable;
import android.app.Activity;
import android.media.SoundPool;
import android.graphics.Paint;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Toast;
import java.util.List;
import static androidx.core.graphics.drawable.IconCompat.getResources;
public class ROPE extends Activity {
public List<Float> ab=[,,,];
public List <Float> ord;
public float speed_up=-1;
public final TARZAN tarzan;
public static final float WIDTH = 67;
public static final float HEIGHT = 416;
public static final float ROPE_DISTANCE = 50;
private static final float SPEED = -2;
public ROPE (Context context, List ab, List ord, TARZAN tarzan){
this.tarzan=tarzan;
}
public void move_rope(){
for(int i=0;i<4;i++){
}
}
public void draw(Canvas canvas) {
Drawable rope= getResources().getDrawable(R.drawable.rope);
rope.draw(canvas);
}
}
Player class:
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.Drawable;
import android.media.SoundPool;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Matrix;
import android.graphics.Rect;
import android.view.GestureDetector;
import android.view.GestureDetector.SimpleOnGestureListener;
import android.view.MotionEvent;
import android.view.View;
import android.view.View.OnTouchListener;
import android.widget.Toast;
public abstract class TARZAN extends Activity implements View.OnClickListener{
private static final int SWIPE_MIN_DISTANCE = 120;
private static final int SWIPE_MAX_OFF_PATH = 250;
private static final int SWIPE_THRESHOLD_VELOCITY = 200;
private GestureDetector gestureDetector;
View.OnTouchListener gestureListener;
private boolean isAlive=true;
public final float K=20;
public final int WIDTH = 44;
public final int HEIGHT = 31;
private final int BASE_COLLISION = 521 - HEIGHT - 5;
public float X;
public float Y;
public float vitesse=0;
static final int gravity = -10; // constant downward acceleration
static final int flapping = 25; // upward acceleration whenever isFlapping is true
Boolean isFlapping = false; // Is TARZAN flapping
public TARZAN(float X,float Y) {
this.X=X;
this.Y=Y;
}
public float getX () {
return X;
}
public float getY () {
return Y;
}
public boolean isAlive () {
return isAlive;
}
/**
* Kills
*/
public void kill () {
isAlive = false;
}
/**
* Set new coordinates when starting game
*/
public void setGameStartPos () {
X = 90;
Y = 500;
}
class MyGestureDetector extends SimpleOnGestureListener {
@Override
public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
try {
if (Math.abs(e1.getY() - e2.getY()) > SWIPE_MAX_OFF_PATH)
return false;
// right to left swipe
if(e1.getX() - e2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
X-=K;
Y=
} else if (e2.getX() - e1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) {
X+=K;
Y=
}
} catch (Exception e) {
// nothing
}
return false;
}
@Override
public boolean onDown(MotionEvent e) {
return true;
}
}
public void stick_to_rope(){
}
public void draw(Canvas canvas) {
Drawable tarzan=getResources().getDrawable(R.drawable.mario);
tarzan.draw(canvas);
}
}
My Main_Activity is currently empty.
GLSurfaceView
toonDrawFrame
inGLSurfaceView.Renderer
?. Although that question focuses onGLSurfaceView
(which you may or may not be using), I think you could find it useful. – Theraot Apr 06 '20 at 10:11