card scalling
This commit is contained in:
@@ -2,7 +2,6 @@ package com.iutlaval.myapplication.Game.Decks;
|
||||
|
||||
import android.content.Context;
|
||||
|
||||
import com.iutlaval.myapplication.Game.HandActivity;
|
||||
|
||||
import java.util.Objects;
|
||||
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
package com.iutlaval.myapplication.Game;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.BitmapFactory;
|
||||
import android.os.Bundle;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||
import com.iutlaval.myapplication.Game.Cards.DemoCard;
|
||||
import com.iutlaval.myapplication.Game.Decks.Deck;
|
||||
import com.iutlaval.myapplication.Game.Decks.DeckDemo;
|
||||
import com.iutlaval.myapplication.GameActivity;
|
||||
@@ -76,7 +73,7 @@ public class GameLogicThread extends Thread{
|
||||
for(Card c : localPlayerHand.getHand())
|
||||
{
|
||||
renderer.addToDraw(c.getDrawableCard());
|
||||
renderer.moveToDraw(i*DrawableCard.CARD_WITH,90F,c.getDrawableCard().getName());
|
||||
renderer.moveToDraw(i* DrawableCard.CARD_WITH,90F,c.getDrawableCard().getName());
|
||||
i++;
|
||||
}
|
||||
|
||||
@@ -105,6 +102,10 @@ public class GameLogicThread extends Thread{
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
private DrawableCard currentlySelected = null;
|
||||
private static final float SELECTING_OFFSET = 20F;
|
||||
/**
|
||||
* relais l'evenement directement au touch Handler
|
||||
* @param event
|
||||
@@ -114,22 +115,21 @@ public class GameLogicThread extends Thread{
|
||||
float unscalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
||||
if(unscalled_Y >= 90F) {
|
||||
float unscalled_X = event.getX() / GameActivity.screenWidth * 100;
|
||||
//TODO : display fullscreen cards
|
||||
Intent HandActivity = new Intent(gameActivity, HandActivity.class);
|
||||
String[] serializedHand = new String[localPlayerHand.getHand().size() +1];
|
||||
int i = 0;
|
||||
serializedHand[i] = localPlayerDeck.getDeckName();
|
||||
for(Card c : localPlayerHand.getHand())
|
||||
DrawableCard smallCArd = renderer.getCardOn(unscalled_X,unscalled_Y);
|
||||
if(smallCArd !=null)
|
||||
{
|
||||
i++;
|
||||
serializedHand[i] = c.getName();
|
||||
|
||||
if(currentlySelected !=null)
|
||||
{
|
||||
currentlySelected.setCoordinates(currentlySelected.getX(),currentlySelected.getY() + SELECTING_OFFSET);
|
||||
renderer.removeToDraw(currentlySelected.getName()+"BIG");
|
||||
}
|
||||
currentlySelected = smallCArd;
|
||||
DrawableCard bigCard = new DrawableCard(smallCArd,cont,2);
|
||||
renderer.addToDraw(bigCard);
|
||||
bigCard.setCoordinates(50F,50F);
|
||||
smallCArd.setCoordinates(smallCArd.getX(),smallCArd.getY() - SELECTING_OFFSET);
|
||||
touch.onTouchEvent(event);
|
||||
}
|
||||
HandActivity.putExtra("hand",serializedHand);
|
||||
Bundle cardSelectedBundle = new Bundle();
|
||||
gameActivity.startActivity(HandActivity,cardSelectedBundle);
|
||||
|
||||
|
||||
}else{
|
||||
touch.onTouchEvent(event);
|
||||
}
|
||||
|
||||
@@ -1,30 +0,0 @@
|
||||
package com.iutlaval.myapplication.Game;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
|
||||
import com.iutlaval.myapplication.Game.Decks.Deck;
|
||||
import com.iutlaval.myapplication.Game.Decks.DeckRegister;
|
||||
import com.iutlaval.myapplication.R;
|
||||
|
||||
public class HandActivity extends AppCompatActivity {
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
setContentView(R.layout.activity_hand);
|
||||
|
||||
String[] serializedHand = getIntent().getStringArrayExtra("hand");
|
||||
Deck d = DeckRegister.getClassFromName(serializedHand[0],this);
|
||||
|
||||
|
||||
Intent data = new Intent();
|
||||
String text = "Result to be returned....";
|
||||
//---set the data to pass back---
|
||||
data.setData(Uri.parse(text));
|
||||
setResult(RESULT_OK, data);
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,8 @@
|
||||
package com.iutlaval.myapplication.Game;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.view.MotionEvent;
|
||||
|
||||
import com.iutlaval.myapplication.GameActivity;
|
||||
import com.iutlaval.myapplication.MainActivity;
|
||||
import com.iutlaval.myapplication.Video.Drawables.DrawableCard;
|
||||
import com.iutlaval.myapplication.Video.Renderer;
|
||||
|
||||
@@ -24,22 +22,27 @@ public class TouchHandler {
|
||||
|
||||
|
||||
public void onTouchEvent(MotionEvent event){
|
||||
|
||||
//on ignore le multi touch
|
||||
if(event.getPointerCount() <= 1)
|
||||
{
|
||||
float unscalled_X = event.getX() / GameActivity.screenWidth * 100;
|
||||
float unscalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
||||
float unscaled_X = event.getX() / GameActivity.screenWidth * 100;
|
||||
float unscaled_Y = event.getY() / GameActivity.screenHeight * 100;
|
||||
|
||||
if (event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||
if(unscalled_Y <= 90F) {
|
||||
moveEventCard = renderer.getCardOn(unscalled_X, unscalled_Y);
|
||||
if (moveEventCard != null) {
|
||||
TouchDeltaY = unscalled_Y - moveEventCard.getY();
|
||||
TouchDeltaX = unscalled_X - moveEventCard.getX();
|
||||
originalPositionX = moveEventCard.getX();
|
||||
originalPositionY = moveEventCard.getY();
|
||||
}
|
||||
if(unscaled_Y <= 90F)
|
||||
{
|
||||
moveEventCard = renderer.getCardOn(unscaled_X, unscaled_Y -20F);
|
||||
}else{
|
||||
moveEventCard = renderer.getCardOn(unscaled_X, unscaled_Y);
|
||||
}
|
||||
|
||||
if (moveEventCard != null) {
|
||||
TouchDeltaY = unscaled_Y - moveEventCard.getY();
|
||||
TouchDeltaX = unscaled_X - moveEventCard.getX();
|
||||
originalPositionX = moveEventCard.getX();
|
||||
originalPositionY = moveEventCard.getY();
|
||||
}
|
||||
|
||||
} else if (event.getAction() == MotionEvent.ACTION_UP) {
|
||||
TouchDeltaY = 0;
|
||||
TouchDeltaX = 0;
|
||||
@@ -47,7 +50,7 @@ public class TouchHandler {
|
||||
if(moveEventCard != null)renderer.moveToDraw(originalPositionX,originalPositionY,moveEventCard.getName());
|
||||
moveEventCard = null;
|
||||
} else if (moveEventCard != null) {
|
||||
moveEventCard.setCoordinates(unscalled_X - TouchDeltaX, unscalled_Y - TouchDeltaY);
|
||||
moveEventCard.setCoordinates(unscaled_X - TouchDeltaX, unscaled_Y - TouchDeltaY);
|
||||
renderer.updateFrame();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user