fix du text + ajout du scalling + big card + fix drag and drop
This commit is contained in:
@@ -131,10 +131,9 @@ public abstract class Card {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* NE PAS OVERRIDE CETTE FONCTION
|
|
||||||
* @return
|
* @return
|
||||||
*/
|
*/
|
||||||
public DrawableCard getDrawableCard() {
|
public final DrawableCard getDrawableCard() {
|
||||||
return drawableCard;
|
return drawableCard;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ package com.iutlaval.myapplication.Game;
|
|||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapFactory;
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
import com.iutlaval.myapplication.Game.Cards.Card;
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
@@ -25,19 +26,18 @@ public class GameLogicThread extends Thread{
|
|||||||
private Deck localPlayerDeck;
|
private Deck localPlayerDeck;
|
||||||
private Hand localPlayerHand;
|
private Hand localPlayerHand;
|
||||||
|
|
||||||
|
|
||||||
public GameLogicThread(GameActivity gameActivity, Renderer renderer)
|
public GameLogicThread(GameActivity gameActivity, Renderer renderer)
|
||||||
{
|
{
|
||||||
ready=false;
|
ready=false;
|
||||||
this.cont = gameActivity;
|
this.cont = gameActivity;
|
||||||
this.renderer = renderer;
|
this.renderer = renderer;
|
||||||
renderer.setEngine(this);
|
|
||||||
touch = new TouchHandler(renderer);
|
touch = new TouchHandler(renderer);
|
||||||
localPlayerDeck = new DeckDemo("local",cont);
|
localPlayerDeck = new DeckDemo("local",cont);
|
||||||
localPlayerDeck.suffle();
|
localPlayerDeck.suffle();
|
||||||
localPlayerHand = new Hand();
|
localPlayerHand = new Hand();
|
||||||
localPlayerHand.fillHand(localPlayerDeck);
|
localPlayerHand.fillHand(localPlayerDeck);
|
||||||
this.gameActivity=gameActivity;
|
this.gameActivity=gameActivity;
|
||||||
|
GameActivity.setGameEngine(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
private float i=0;
|
private float i=0;
|
||||||
@@ -46,17 +46,10 @@ public class GameLogicThread extends Thread{
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
Log.e("RESOLUTION:",""+GameActivity.screenWidth+"x"+GameActivity.screenHeight);
|
||||||
//affichage de l'arriere plan
|
//affichage de l'arriere plan
|
||||||
Bitmap bitmap= BitmapFactory.decodeResource(cont.getResources(), R.drawable.t_b_board_background);
|
Bitmap bitmap= BitmapFactory.decodeResource(cont.getResources(), R.drawable.t_b_board_background);
|
||||||
renderer.addToDraw(new Drawable(bitmap, 0,0, "background", 100, 100 ));
|
renderer.addToDraw(new Drawable(bitmap, 0,0, "background", 100, 100 ));
|
||||||
|
|
||||||
//renderer.addToDraw(new Drawable(bm,0.0F,0.0F,"running",8F,16F));
|
|
||||||
//renderer.addToDraw(new DrawableCard(new DemoCard(),0.0F,0.0F,"card2",cont));
|
|
||||||
/*Card card2 = new DemoCard("card3",cont);
|
|
||||||
renderer.addToDraw(card2.getDrawableCard());
|
|
||||||
Card card1 = new DemoCard("card1",cont);
|
|
||||||
renderer.addToDraw(card1.getDrawableCard());*/
|
|
||||||
|
|
||||||
drawHandPreview();
|
drawHandPreview();
|
||||||
|
|
||||||
ready=true;
|
ready=true;
|
||||||
@@ -113,7 +106,7 @@ public class GameLogicThread extends Thread{
|
|||||||
public void onTouchEvent(MotionEvent event) {
|
public void onTouchEvent(MotionEvent event) {
|
||||||
if(isReady()){
|
if(isReady()){
|
||||||
float unscalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
float unscalled_Y = event.getY() / GameActivity.screenHeight * 100;
|
||||||
if(unscalled_Y >= 90F) {
|
if(unscalled_Y >= 90F && event.getAction() == MotionEvent.ACTION_DOWN) {
|
||||||
float unscalled_X = event.getX() / GameActivity.screenWidth * 100;
|
float unscalled_X = event.getX() / GameActivity.screenWidth * 100;
|
||||||
DrawableCard smallCArd = renderer.getCardOn(unscalled_X,unscalled_Y);
|
DrawableCard smallCArd = renderer.getCardOn(unscalled_X,unscalled_Y);
|
||||||
if(smallCArd !=null)
|
if(smallCArd !=null)
|
||||||
@@ -121,15 +114,25 @@ public class GameLogicThread extends Thread{
|
|||||||
if(currentlySelected !=null)
|
if(currentlySelected !=null)
|
||||||
{
|
{
|
||||||
currentlySelected.setCoordinates(currentlySelected.getX(),currentlySelected.getY() + SELECTING_OFFSET);
|
currentlySelected.setCoordinates(currentlySelected.getX(),currentlySelected.getY() + SELECTING_OFFSET);
|
||||||
renderer.removeToDraw(currentlySelected.getName()+"BIG");
|
//on update pas affin d'avoir un rendu plus fluide au moment de mettre l'aure carte
|
||||||
|
renderer.removeToDrawWithoutUpdate(currentlySelected.getName()+"BIG");
|
||||||
}
|
}
|
||||||
currentlySelected = smallCArd;
|
currentlySelected = smallCArd;
|
||||||
DrawableCard bigCard = new DrawableCard(smallCArd,cont,2);
|
DrawableCard bigCard = new DrawableCard(smallCArd,cont,2);
|
||||||
renderer.addToDraw(bigCard);
|
renderer.addToDraw(bigCard);
|
||||||
bigCard.setCoordinates(50F,50F);
|
bigCard.setCoordinates(72F,10F);
|
||||||
smallCArd.setCoordinates(smallCArd.getX(),smallCArd.getY() - SELECTING_OFFSET);
|
smallCArd.setCoordinates(smallCArd.getX(),smallCArd.getY() - SELECTING_OFFSET);
|
||||||
touch.onTouchEvent(event);
|
touch.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
}else if(event.getAction() == MotionEvent.ACTION_UP){
|
||||||
|
//currentlySelected.setCoordinates(currentlySelected.getX(),currentlySelected.getY() + SELECTING_OFFSET);
|
||||||
|
touch.onTouchEvent(event);
|
||||||
|
if(currentlySelected !=null)
|
||||||
|
{
|
||||||
|
renderer.removeToDraw(currentlySelected.getName()+"BIG");
|
||||||
|
currentlySelected.setCoordinates(currentlySelected.getX(),currentlySelected.getY() + SELECTING_OFFSET);
|
||||||
|
currentlySelected=null;
|
||||||
|
}
|
||||||
}else{
|
}else{
|
||||||
touch.onTouchEvent(event);
|
touch.onTouchEvent(event);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import android.app.Activity;
|
|||||||
import android.content.pm.ActivityInfo;
|
import android.content.pm.ActivityInfo;
|
||||||
import android.graphics.Point;
|
import android.graphics.Point;
|
||||||
import android.os.Bundle;
|
import android.os.Bundle;
|
||||||
|
import android.util.Log;
|
||||||
import android.view.Display;
|
import android.view.Display;
|
||||||
import android.view.MotionEvent;
|
import android.view.MotionEvent;
|
||||||
|
|
||||||
@@ -24,7 +25,7 @@ public class GameActivity extends Activity {
|
|||||||
public static boolean isMultiplayer() {
|
public static boolean isMultiplayer() {
|
||||||
return false;//TODO implement it
|
return false;//TODO implement it
|
||||||
}
|
}
|
||||||
|
private Renderer renderer;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
@@ -34,35 +35,21 @@ public class GameActivity extends Activity {
|
|||||||
Display display = getWindowManager().getDefaultDisplay();
|
Display display = getWindowManager().getDefaultDisplay();
|
||||||
FpsTime.init(display);
|
FpsTime.init(display);
|
||||||
|
|
||||||
Renderer renderer = new Renderer(getBaseContext());
|
renderer = new Renderer(getBaseContext(),this);
|
||||||
|
|
||||||
//nous donne la resolution
|
|
||||||
Point size = new Point();
|
|
||||||
display.getSize(size);
|
|
||||||
|
|
||||||
//vu que l'on verouille en mode portrait en veut juste la resolution en 16:9 et non en 9:16
|
|
||||||
//donc on prend celui le plus large
|
|
||||||
//en cas de la de la machine les peuvent s'inverser d'ou l'interet du test
|
|
||||||
if(size.y > size.x)
|
|
||||||
{
|
|
||||||
screenWidth = size.y;
|
|
||||||
screenHeight = size.x;
|
|
||||||
}else{
|
|
||||||
screenWidth = size.x;
|
|
||||||
screenHeight = size.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
gameEngine = new GameLogicThread(this,renderer);
|
|
||||||
gameEngine.start();
|
|
||||||
|
|
||||||
setContentView(renderer);
|
setContentView(renderer);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void setGameEngine(GameLogicThread gameEngine) {
|
||||||
|
GameActivity.gameEngine = gameEngine;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean onTouchEvent(MotionEvent event) {
|
public boolean onTouchEvent(MotionEvent event) {
|
||||||
if(gameEngine != null)gameEngine.onTouchEvent(event);
|
if(gameEngine != null)gameEngine.onTouchEvent(event);
|
||||||
return super.onTouchEvent(event);
|
return super.onTouchEvent(event);
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
final Button playButton = (Button) findViewById(R.id.playButton);
|
final Button playButton = (Button) findViewById(R.id.playButton);
|
||||||
playButton.setOnClickListener(new View.OnClickListener() {
|
playButton.setOnClickListener(new View.OnClickListener() {
|
||||||
public void onClick(View v) {
|
public void onClick(View v) {
|
||||||
Toast.makeText(getApplicationContext(), "click sur button", Toast.LENGTH_LONG).show();
|
//Toast.makeText(getApplicationContext(), "click sur button", Toast.LENGTH_LONG).show();
|
||||||
Intent gameActivity = new Intent(MainActivity.this, GameActivity.class);
|
Intent gameActivity = new Intent(MainActivity.this, GameActivity.class);
|
||||||
|
|
||||||
startActivity(gameActivity);
|
startActivity(gameActivity);
|
||||||
|
|||||||
@@ -55,52 +55,13 @@ public class Drawable {
|
|||||||
|
|
||||||
if(x_scaled_size <=0 || y_scaled_size <=0)
|
if(x_scaled_size <=0 || y_scaled_size <=0)
|
||||||
{
|
{
|
||||||
Log.e("TEXTURE :","ERREUR DE MISE A L'ECHELLE");
|
Log.e("DRAWABLE_TEXTURE :","ERREUR DE MISE A L'ECHELLE");
|
||||||
System.exit(ERROR_CODE.ERROR_TEXTURE_DIMENSIONS_INVALID.ordinal());
|
System.exit(ERROR_CODE.ERROR_TEXTURE_DIMENSIONS_INVALID.ordinal());
|
||||||
}
|
}
|
||||||
|
|
||||||
this.bitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size, GameActivity.bilinearFiltering);
|
this.bitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size, GameActivity.bilinearFiltering);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**TODO : corriger les deformation due au changement de ratio (x_size,y_size)
|
|
||||||
* ce constructeur permet de rendre du texte
|
|
||||||
* @param text le texte a rendre
|
|
||||||
* @param x_pos position en x du texte
|
|
||||||
* @param y_pos position en y du texte
|
|
||||||
* @param name nom du Drawable
|
|
||||||
* @param x_size taille du drawable entre 0 et 100
|
|
||||||
* @param y_size taille du drawable entre 0 et 100
|
|
||||||
*/
|
|
||||||
public Drawable(String text,float x_pos,float y_pos,String name, float x_size,float y_size,float textSize , int x_canvasRatio, int y_canvasRatio)
|
|
||||||
{
|
|
||||||
this(x_pos,y_pos,name);
|
|
||||||
|
|
||||||
checkPaint();
|
|
||||||
p.setColor(Color.BLACK);
|
|
||||||
p.setAntiAlias(true);
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
List<String> linesOfText = cutText(20,text);
|
|
||||||
p.setTextSize(textSize);
|
|
||||||
|
|
||||||
//+10 permet d'e prendre en compte les p,q,j qui dessende plus bas que les autres
|
|
||||||
bitmap = Bitmap.createBitmap(x_canvasRatio, y_canvasRatio, Bitmap.Config.ARGB_8888);
|
|
||||||
Canvas c = new Canvas(bitmap);
|
|
||||||
|
|
||||||
int index = 1;
|
|
||||||
for(String line : linesOfText)
|
|
||||||
{
|
|
||||||
c.drawText(line ,0,index*y_canvasRatio/linesOfText.size(),p);
|
|
||||||
index++;
|
|
||||||
}
|
|
||||||
|
|
||||||
int scalled_x_size = (int)(GameActivity.screenWidth*x_size/100);
|
|
||||||
int scalled_y_size = (int)(GameActivity.screenHeight*y_size/100);
|
|
||||||
|
|
||||||
bitmap = Bitmap.createScaledBitmap(bitmap,scalled_x_size,scalled_y_size,GameActivity.bilinearFiltering);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ce constructeur n'est pas rapide essayer de l'utiliser le moin possible
|
* ce constructeur n'est pas rapide essayer de l'utiliser le moin possible
|
||||||
@@ -244,4 +205,17 @@ public class Drawable {
|
|||||||
protected void scale(float i) {
|
protected void scale(float i) {
|
||||||
bitmap = Bitmap.createScaledBitmap(this.bitmap,(int)(bitmap.getWidth()*i),(int)(bitmap.getHeight()*i),GameActivity.bilinearFiltering);
|
bitmap = Bitmap.createScaledBitmap(this.bitmap,(int)(bitmap.getWidth()*i),(int)(bitmap.getHeight()*i),GameActivity.bilinearFiltering);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retourne si le drawable peut être deplacer en drag and drop
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public boolean isDraggable() {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void setBitmap(Bitmap bitmap)
|
||||||
|
{
|
||||||
|
this.bitmap=bitmap;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,16 +22,16 @@ public class DrawableCard extends Drawable{
|
|||||||
|
|
||||||
public static final int CARD_WITH = 14;
|
public static final int CARD_WITH = 14;
|
||||||
private static final int CARD_HEIGHT = 40;
|
private static final int CARD_HEIGHT = 40;
|
||||||
private static final float HP_ATK_FONT_SIZE_BIG_CARD =30F;
|
private static final float HP_ATK_FONT_SIZE_OFFBOARD =60F;
|
||||||
private static final float HP_ATK_FONT_SIZE_BOARD =70F;
|
private static final float HP_ATK_FONT_SIZE_BOARD =70F;
|
||||||
private static final float DESCRIPTION_FONT_SIZE =30F;
|
private static final float DESCRIPTION_FONT_SIZE =26F;
|
||||||
private static final float TITLE_FONT_SIZE =30F;
|
private static final float TITLE_FONT_SIZE =30F;
|
||||||
private static int DESCRIPTION_TEXT_X_RES = 281;
|
private static int DESCRIPTION_TEXT_X_RES = 281;
|
||||||
private static int DESCRIPTION_TEXT_Y_RES = 195;
|
private static int DESCRIPTION_TEXT_Y_RES = 195;
|
||||||
private static int TEXT_TITLE_X_RES = 281;
|
private static int TEXT_TITLE_X_RES = 281;
|
||||||
private static int TEXT_TITLE_Y_RES = 60;
|
private static int TEXT_TITLE_Y_RES = 60;
|
||||||
private static int TEXT_ATK_HP_X_RES = 110;
|
private static int TEXT_ATK_HP_X_RES = 110;
|
||||||
private static int TEXT_ATK_HP_Y_RES = 60;
|
private static int TEXT_ATK_HP_Y_RES = 60;//60
|
||||||
|
|
||||||
//des floats sont utiliser card ils prenne moin de ram que des doubles et que l'on a pas besoin de la precision supplementaire
|
//des floats sont utiliser card ils prenne moin de ram que des doubles et que l'on a pas besoin de la precision supplementaire
|
||||||
//dimentions
|
//dimentions
|
||||||
@@ -39,8 +39,8 @@ public class DrawableCard extends Drawable{
|
|||||||
private static final float ONBOARD_RECTANGLE_ATK_HP_HEIGHT = CARD_HEIGHT * 0.2F;
|
private static final float ONBOARD_RECTANGLE_ATK_HP_HEIGHT = CARD_HEIGHT * 0.2F;
|
||||||
private static final float ONBOARD_ATK_HP_WIDTH = 0.4F * CARD_WITH;
|
private static final float ONBOARD_ATK_HP_WIDTH = 0.4F * CARD_WITH;
|
||||||
private static final float ONBOARD_ATK_HP_HEIGHT = 0.125F * CARD_HEIGHT;
|
private static final float ONBOARD_ATK_HP_HEIGHT = 0.125F * CARD_HEIGHT;
|
||||||
private static final float OFFBOARD_ATK_HP_WIDTH = 0.5F * CARD_WITH;
|
private static final float OFFBOARD_ATK_HP_WIDTH = 0.25F * CARD_WITH;
|
||||||
private static final float OFFBOARD_ATK_HP_HEIGHT = 0.2F * CARD_HEIGHT;
|
private static final float OFFBOARD_ATK_HP_HEIGHT = 0.08F * CARD_HEIGHT;
|
||||||
|
|
||||||
private static final float DESCRIPTION_WIDTH = CARD_WITH*0.9F;
|
private static final float DESCRIPTION_WIDTH = CARD_WITH*0.9F;
|
||||||
private static final float DESCRIPTION_HEIGHT = CARD_HEIGHT*0.35F;
|
private static final float DESCRIPTION_HEIGHT = CARD_HEIGHT*0.35F;
|
||||||
@@ -69,21 +69,22 @@ public class DrawableCard extends Drawable{
|
|||||||
private static final float OFFBOARD_PICTURE_X = 0.0787F * CARD_WITH;
|
private static final float OFFBOARD_PICTURE_X = 0.0787F * CARD_WITH;
|
||||||
private static final float OFFBOARD_PICTURE_Y = 0.0834F * CARD_HEIGHT;
|
private static final float OFFBOARD_PICTURE_Y = 0.0834F * CARD_HEIGHT;
|
||||||
private static final float OFFBOARD_DESCRIPTION_X = 0.07F * CARD_WITH;
|
private static final float OFFBOARD_DESCRIPTION_X = 0.07F * CARD_WITH;
|
||||||
private static final float OFFBOARD_DESCRIPTION_Y = 0.455F * CARD_HEIGHT;
|
private static final float OFFBOARD_DESCRIPTION_Y = 0.45F * CARD_HEIGHT;
|
||||||
private static final float OFFBOARD_ATK_X = 0.08F * CARD_WITH;
|
private static final float OFFBOARD_ATK_X = 0.08F * CARD_WITH;
|
||||||
private static final float OFFBOARD_ATK_Y = 0.735F * CARD_HEIGHT;
|
private static final float OFFBOARD_HP_X = 0.71F * CARD_WITH;
|
||||||
private static final float OFFBOARD_HP_X = 0.7F * CARD_WITH;
|
private static final float OFFBOARD_ATK_HP_Y = 0.85F * CARD_HEIGHT;//735F pour un ration de 2
|
||||||
private static final float OFFBOARD_HP_Y = 0.735F * CARD_HEIGHT;
|
|
||||||
private static final float OFFBOARD_TITLE_X =0.1F * CARD_WITH;
|
private static final float OFFBOARD_TITLE_X =0.1F * CARD_WITH;
|
||||||
private static final float OFFBOARD_TITLE_Y = 0.025F * CARD_HEIGHT;
|
private static final float OFFBOARD_TITLE_Y = -0.025F * CARD_HEIGHT;
|
||||||
|
|
||||||
private static final float CARD_ON_BOARD_DRAWABLE_WIDTH = CARD_WITH;
|
private static final float CARD_ON_BOARD_DRAWABLE_WIDTH = CARD_WITH;
|
||||||
private static final float CARD_ON_BOARD_DRAWABLE_HEIGHT = CARD_HEIGHT*0.667F;
|
private static final float CARD_ON_BOARD_DRAWABLE_HEIGHT = CARD_HEIGHT*0.667F;
|
||||||
|
|
||||||
private Boolean onBoard;
|
private Boolean onBoard;
|
||||||
|
private Boolean draggable;
|
||||||
|
|
||||||
private Drawable OpacityRectangleDrawable;
|
private Drawable frameDrawable;
|
||||||
private Drawable PictureDrawable;
|
private Drawable opacityRectangleDrawable;
|
||||||
|
private Drawable pictureDrawable;
|
||||||
|
|
||||||
private Drawable cardOnBoardDrawable;
|
private Drawable cardOnBoardDrawable;
|
||||||
|
|
||||||
@@ -142,21 +143,25 @@ public class DrawableCard extends Drawable{
|
|||||||
* donc les coodonées ne se trouve que dans cette fonction
|
* donc les coodonées ne se trouve que dans cette fonction
|
||||||
*/
|
*/
|
||||||
public DrawableCard(Card c, float x, float y, String name, Context context,int ratio){
|
public DrawableCard(Card c, float x, float y, String name, Context context,int ratio){
|
||||||
super(c.getFrameBitmap(context),x,y,name,CARD_WITH*ratio,CARD_HEIGHT*ratio);
|
super(x,y,name);
|
||||||
this.ratio=ratio;
|
//super(c.getFrameBitmap(context),x,y,name,CARD_WITH*ratio,CARD_HEIGHT*ratio);//todo replace this with a con
|
||||||
card=c;
|
|
||||||
onBoard=false;
|
|
||||||
|
|
||||||
|
this.draggable =true;
|
||||||
|
this.onBoard=false;
|
||||||
|
this.ratio=ratio;
|
||||||
|
this.card=c;
|
||||||
|
|
||||||
|
frameDrawable = new Drawable(c.getFrameBitmap(context),0,0,name+"frame",CARD_WITH*ratio,CARD_HEIGHT*ratio);
|
||||||
//to string retourne le hash code de l'objet qui est donc unique ce qui fait de lui un id parfait
|
//to string retourne le hash code de l'objet qui est donc unique ce qui fait de lui un id parfait
|
||||||
cardDescription = new Drawable(c.getDescription(),0,0,toString()+"description",DESCRIPTION_WIDTH*ratio,DESCRIPTION_HEIGHT*ratio,DESCRIPTION_FONT_SIZE*ratio,DESCRIPTION_TEXT_X_RES*ratio,DESCRIPTION_TEXT_Y_RES*ratio);
|
cardDescription = new DrawableText(c.getDescription(),0,0,toString()+"description",DESCRIPTION_WIDTH*ratio,DESCRIPTION_HEIGHT*ratio,DESCRIPTION_FONT_SIZE,DESCRIPTION_TEXT_X_RES,DESCRIPTION_TEXT_Y_RES);
|
||||||
cardTitle = new Drawable(c.getName(),0,0,toString()+"name",TITLE_WIDTH*ratio,TITLE_HEIGHT*ratio,TITLE_FONT_SIZE*ratio,TEXT_TITLE_X_RES*ratio,TEXT_TITLE_Y_RES*ratio);
|
cardTitle = new DrawableText(c.getName(),0,0,toString()+"name",TITLE_WIDTH*ratio,TITLE_HEIGHT*ratio,TITLE_FONT_SIZE,TEXT_TITLE_X_RES,TEXT_TITLE_Y_RES);
|
||||||
|
|
||||||
Rectangle opacityRect = new Rectangle(x,y,OPACITY_RECT_WIDTH*ratio+x,OPACITY_RECT_HEIGHT*ratio+x);
|
Rectangle opacityRect = new Rectangle(x,y,OPACITY_RECT_WIDTH*ratio+x,OPACITY_RECT_HEIGHT*ratio+x);
|
||||||
Bitmap pictureBitmap = BitmapFactory.decodeResource(context.getResources(),c.getCardPicture());
|
Bitmap pictureBitmap = BitmapFactory.decodeResource(context.getResources(),c.getCardPicture());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
OpacityRectangleDrawable = new Drawable(opacityRect,toString()+"Opacity", Color.parseColor(c.getColor()));
|
opacityRectangleDrawable = new Drawable(opacityRect,toString()+"Opacity", Color.parseColor(c.getColor()));
|
||||||
PictureDrawable = new Drawable(pictureBitmap,0,0,toString()+"Picture",PICTURE_WIDTH*ratio,PICTURE_HEIGHT*ratio);
|
pictureDrawable = new Drawable(pictureBitmap,0,0,toString()+"Picture",PICTURE_WIDTH*ratio,PICTURE_HEIGHT*ratio);
|
||||||
} catch (InvalidDataException e) {
|
} catch (InvalidDataException e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
Log.e("CARTE :","forme de la carte invalide !");
|
Log.e("CARTE :","forme de la carte invalide !");
|
||||||
@@ -192,6 +197,7 @@ public class DrawableCard extends Drawable{
|
|||||||
|
|
||||||
public DrawableCard(DrawableCard smallCArd, Context cont,int ratio) {
|
public DrawableCard(DrawableCard smallCArd, Context cont,int ratio) {
|
||||||
this(smallCArd.card,smallCArd.getX(),smallCArd.getY(),smallCArd.getName()+"BIG",cont,ratio);
|
this(smallCArd.card,smallCArd.getX(),smallCArd.getY(),smallCArd.getName()+"BIG",cont,ratio);
|
||||||
|
draggable =false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -208,14 +214,14 @@ public class DrawableCard extends Drawable{
|
|||||||
{
|
{
|
||||||
if(onBoard) {
|
if(onBoard) {
|
||||||
if (atk != null)
|
if (atk != null)
|
||||||
cardAtkDrawable = new Drawable(atk+"", 0, 0, toString() + "atk", ONBOARD_ATK_HP_WIDTH*ratio, ONBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE_BOARD*ratio,TEXT_ATK_HP_X_RES*ratio,TEXT_ATK_HP_Y_RES*ratio);
|
cardAtkDrawable = new DrawableText(atk+"", 0, 0, toString() + "atk", ONBOARD_ATK_HP_WIDTH*ratio, ONBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE_BOARD,TEXT_ATK_HP_X_RES,TEXT_ATK_HP_Y_RES);
|
||||||
if (hp != null)
|
if (hp != null)
|
||||||
cardHpDrawable = new Drawable(hp+"", 0, 0, toString() + "hp", ONBOARD_ATK_HP_WIDTH*ratio, ONBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE_BOARD*ratio,TEXT_ATK_HP_X_RES*ratio,TEXT_ATK_HP_Y_RES*ratio);
|
cardHpDrawable = new DrawableText(hp+"", 0, 0, toString() + "hp", ONBOARD_ATK_HP_WIDTH*ratio, ONBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE_BOARD,TEXT_ATK_HP_X_RES,TEXT_ATK_HP_Y_RES);
|
||||||
}else{
|
}else{
|
||||||
if (atk != null)
|
if (atk != null)
|
||||||
cardAtkDrawable = new Drawable(atk + "", 0, 0, toString() + "atk", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE_BIG_CARD*ratio,TEXT_ATK_HP_X_RES*ratio,TEXT_ATK_HP_Y_RES*ratio);
|
cardAtkDrawable = new DrawableText(atk + "", 0, 0, toString() + "atk", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE_OFFBOARD, TEXT_ATK_HP_X_RES, TEXT_ATK_HP_Y_RES);
|
||||||
if (hp != null)
|
if (hp != null)
|
||||||
cardHpDrawable = new Drawable(hp + "", 0, 0, toString() + "hp", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE_BIG_CARD*ratio,TEXT_ATK_HP_X_RES*ratio,TEXT_ATK_HP_Y_RES*ratio);
|
cardHpDrawable = new DrawableText(hp + "", 0, 0, toString() + "hp", OFFBOARD_ATK_HP_WIDTH*ratio, OFFBOARD_ATK_HP_HEIGHT*ratio, HP_ATK_FONT_SIZE_OFFBOARD, TEXT_ATK_HP_X_RES, TEXT_ATK_HP_Y_RES);
|
||||||
}
|
}
|
||||||
setCoordinates(getX(), getY());
|
setCoordinates(getX(), getY());
|
||||||
}
|
}
|
||||||
@@ -249,15 +255,15 @@ public class DrawableCard extends Drawable{
|
|||||||
if(onBoard)
|
if(onBoard)
|
||||||
{
|
{
|
||||||
cardOnBoardDrawable.drawOn(c,p);
|
cardOnBoardDrawable.drawOn(c,p);
|
||||||
PictureDrawable.drawOn(c,p);
|
pictureDrawable.drawOn(c,p);
|
||||||
|
|
||||||
cardTitle.drawOn(c,p);
|
cardTitle.drawOn(c,p);
|
||||||
cardHpDrawable.drawOn(c,p);
|
cardHpDrawable.drawOn(c,p);
|
||||||
cardAtkDrawable.drawOn(c,p);
|
cardAtkDrawable.drawOn(c,p);
|
||||||
}else{
|
}else{
|
||||||
super.drawOn(c, p);
|
frameDrawable.drawOn(c,p);
|
||||||
OpacityRectangleDrawable.drawOn(c,p);
|
opacityRectangleDrawable.drawOn(c,p);
|
||||||
PictureDrawable.drawOn(c,p);
|
pictureDrawable.drawOn(c,p);
|
||||||
|
|
||||||
//dessine le texte
|
//dessine le texte
|
||||||
cardTitle.drawOn(c,p);
|
cardTitle.drawOn(c,p);
|
||||||
@@ -279,18 +285,19 @@ public class DrawableCard extends Drawable{
|
|||||||
super.setCoordinates(x, y);
|
super.setCoordinates(x, y);
|
||||||
if (onBoard) {
|
if (onBoard) {
|
||||||
cardOnBoardDrawable.setCoordinates(x,y);
|
cardOnBoardDrawable.setCoordinates(x,y);
|
||||||
PictureDrawable.setCoordinates(x + ONBOARD_PICTURE_X*ratio, y +ONBOARD_PICTURE_Y*ratio);
|
pictureDrawable.setCoordinates(x + ONBOARD_PICTURE_X*ratio, y +ONBOARD_PICTURE_Y*ratio);
|
||||||
cardAtkDrawable.setCoordinates(x+ONBOARD_ATK_X*ratio,y + ONBOARD_ATK_HP_Y*ratio);
|
cardAtkDrawable.setCoordinates(x+ONBOARD_ATK_X*ratio,y + ONBOARD_ATK_HP_Y*ratio);
|
||||||
cardHpDrawable.setCoordinates(x+ONBOARD_HP_X*ratio,y + ONBOARD_ATK_HP_Y*ratio);
|
cardHpDrawable.setCoordinates(x+ONBOARD_HP_X*ratio,y + ONBOARD_ATK_HP_Y*ratio);
|
||||||
cardTitle.setCoordinates(x+ONBOARD_TITLE_X*ratio,y - ONBOARD_TITLE_Y*ratio);
|
cardTitle.setCoordinates(x+ONBOARD_TITLE_X*ratio,y - ONBOARD_TITLE_Y*ratio);
|
||||||
}else{
|
}else{
|
||||||
OpacityRectangleDrawable.setCoordinates(x, y);
|
frameDrawable.setCoordinates(x,y);
|
||||||
PictureDrawable.setCoordinates(x + OFFBOARD_PICTURE_X*ratio, y + OFFBOARD_PICTURE_Y*ratio);
|
opacityRectangleDrawable.setCoordinates(x, y);
|
||||||
|
pictureDrawable.setCoordinates(x + OFFBOARD_PICTURE_X*ratio, y + OFFBOARD_PICTURE_Y*ratio);
|
||||||
|
|
||||||
//les textes ce dessines depuis leur base et non depuis le coin haut gauche
|
//les textes ce dessines depuis leur base et non depuis le coin haut gauche
|
||||||
cardDescription.setCoordinates(x+OFFBOARD_DESCRIPTION_X*ratio,y+OFFBOARD_DESCRIPTION_Y*ratio);
|
cardDescription.setCoordinates(x+OFFBOARD_DESCRIPTION_X*ratio,y+OFFBOARD_DESCRIPTION_Y*ratio);
|
||||||
cardAtkDrawable.setCoordinates(x + OFFBOARD_ATK_X*ratio,y + OFFBOARD_ATK_Y*ratio);
|
cardAtkDrawable.setCoordinates(x + OFFBOARD_ATK_X*ratio,y + OFFBOARD_ATK_HP_Y*ratio);
|
||||||
cardHpDrawable.setCoordinates(x + OFFBOARD_HP_X*ratio,y +OFFBOARD_HP_Y*ratio);
|
cardHpDrawable.setCoordinates(x + OFFBOARD_HP_X*ratio,y +OFFBOARD_ATK_HP_Y*ratio);
|
||||||
cardTitle.setCoordinates(x+OFFBOARD_TITLE_X*ratio,y - OFFBOARD_TITLE_Y*ratio);
|
cardTitle.setCoordinates(x+OFFBOARD_TITLE_X*ratio,y - OFFBOARD_TITLE_Y*ratio);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -319,4 +326,8 @@ public class DrawableCard extends Drawable{
|
|||||||
return CARD_HEIGHT;
|
return CARD_HEIGHT;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean isDraggable() {
|
||||||
|
return draggable;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,50 @@
|
|||||||
|
package com.iutlaval.myapplication.Video.Drawables;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.GameActivity;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class DrawableText extends Drawable{
|
||||||
|
/**TODO : corriger les deformation due au changement de ratio (x_size,y_size)
|
||||||
|
* ce constructeur permet de rendre du texte
|
||||||
|
* @param text le texte a rendre
|
||||||
|
* @param x_pos position en x du texte
|
||||||
|
* @param y_pos position en y du texte
|
||||||
|
* @param name nom du Drawable
|
||||||
|
* @param x_size taille du drawable entre 0 et 100
|
||||||
|
* @param y_size taille du drawable entre 0 et 100
|
||||||
|
*/
|
||||||
|
public DrawableText(String text,float x_pos,float y_pos,String name, float x_size,float y_size,float textSize , int x_canvasRatio, int y_canvasRatio)
|
||||||
|
{
|
||||||
|
super(x_pos,y_pos,name);
|
||||||
|
|
||||||
|
checkPaint();
|
||||||
|
p.setColor(Color.BLACK);
|
||||||
|
p.setAntiAlias(true);
|
||||||
|
p.setTextSize(textSize);
|
||||||
|
|
||||||
|
List<String> linesOfText = cutText(20,text);
|
||||||
|
|
||||||
|
//+10 permet d'e prendre en compte les p,q,j qui dessende plus bas que les autres
|
||||||
|
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap(x_canvasRatio, y_canvasRatio, Bitmap.Config.ARGB_8888);
|
||||||
|
setBitmap(bitmap);
|
||||||
|
Canvas c = new Canvas(bitmap);
|
||||||
|
int index = 1;
|
||||||
|
for(String line : linesOfText)
|
||||||
|
{
|
||||||
|
//y_canvasRatio/linesOfText.size()
|
||||||
|
c.drawText(line ,0,index*textSize,p);
|
||||||
|
index++;
|
||||||
|
}
|
||||||
|
|
||||||
|
int scalled_x_size = (int)(GameActivity.screenWidth*x_size/100);
|
||||||
|
int scalled_y_size = (int)(GameActivity.screenHeight*y_size/100);
|
||||||
|
|
||||||
|
setBitmap(Bitmap.createScaledBitmap(bitmap,scalled_x_size,scalled_y_size,GameActivity.bilinearFiltering));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -24,16 +24,19 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
private Paint p;
|
private Paint p;
|
||||||
private DrawingThread drawingThread;
|
private DrawingThread drawingThread;
|
||||||
private GameLogicThread engine;
|
private GameLogicThread engine;
|
||||||
|
private GameActivity gameActivity;
|
||||||
private boolean contentChanged;
|
private boolean contentChanged;
|
||||||
|
|
||||||
private List<Drawable> toDraw;
|
private List<Drawable> toDraw;
|
||||||
|
|
||||||
public Renderer(Context context) {
|
public Renderer(Context context, GameActivity gameActivity) {
|
||||||
super(context);
|
super(context);
|
||||||
|
this.gameActivity=gameActivity;
|
||||||
|
|
||||||
holder = getHolder();
|
holder = getHolder();
|
||||||
holder.addCallback(this);
|
holder.addCallback(this);
|
||||||
|
|
||||||
drawingThread = new DrawingThread();
|
drawingThread = new DrawingThread(this);
|
||||||
|
|
||||||
p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
|
p = new Paint(Paint.ANTI_ALIAS_FLAG | Paint.DITHER_FLAG);
|
||||||
p.setColor(Color.RED);
|
p.setColor(Color.RED);
|
||||||
@@ -51,7 +54,7 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
this.holder=holder;
|
this.holder=holder;
|
||||||
if(drawingThread.getState() == Thread.State.TERMINATED)
|
if(drawingThread.getState() == Thread.State.TERMINATED)
|
||||||
{
|
{
|
||||||
drawingThread = new DrawingThread();
|
drawingThread = new DrawingThread(this);
|
||||||
}
|
}
|
||||||
if(!drawingThread.isAlive()){
|
if(!drawingThread.isAlive()){
|
||||||
drawingThread.start();
|
drawingThread.start();
|
||||||
@@ -68,9 +71,6 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
*/
|
*/
|
||||||
@Override
|
@Override
|
||||||
public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {
|
public void surfaceChanged(@NonNull SurfaceHolder surfaceHolder, int i, int i1, int i2) {
|
||||||
//mise a jour de la valleur de la resolution car la premiere obtenus est inexact et prends en compte la bare menu
|
|
||||||
GameActivity.screenHeight=surfaceHolder.getSurfaceFrame().height();
|
|
||||||
GameActivity.screenWidth=surfaceHolder.getSurfaceFrame().width();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -113,12 +113,25 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
* main drawing thread render each frame
|
* main drawing thread render each frame
|
||||||
*/
|
*/
|
||||||
private class DrawingThread extends Thread {
|
private class DrawingThread extends Thread {
|
||||||
|
private Renderer renderer;
|
||||||
|
|
||||||
|
public DrawingThread(Renderer renderer)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.renderer=renderer;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean keepDrawing = true;
|
public boolean keepDrawing = true;
|
||||||
|
|
||||||
@SuppressLint("WrongCall")
|
@SuppressLint("WrongCall")
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
|
while(getWidth()==0);
|
||||||
|
GameActivity.screenHeight=renderer.getHeight() < renderer.getWidth() ? renderer.getHeight() : renderer.getWidth();
|
||||||
|
GameActivity.screenWidth=renderer.getHeight() > renderer.getWidth() ? renderer.getHeight() : renderer.getWidth();
|
||||||
|
engine = new GameLogicThread(gameActivity,renderer);
|
||||||
|
engine.start();
|
||||||
|
|
||||||
while (keepDrawing) {
|
while (keepDrawing) {
|
||||||
Canvas canvas = null;
|
Canvas canvas = null;
|
||||||
|
|
||||||
@@ -192,14 +205,22 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
throw new DrawableNotFoundException();
|
throw new DrawableNotFoundException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* supprime le drawable possedant le nom indique mais n'upate pas le renderer
|
||||||
|
* @param name le nom
|
||||||
|
*/
|
||||||
|
public void removeToDrawWithoutUpdate(String name){
|
||||||
|
Drawable d = getDrawAble(name);
|
||||||
|
if(d != null)
|
||||||
|
toDraw.remove(d);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* supprime le drawable possedant le nom indique
|
* supprime le drawable possedant le nom indique
|
||||||
* @param name le nom
|
* @param name le nom
|
||||||
*/
|
*/
|
||||||
public void removeToDraw(String name){
|
public void removeToDraw(String name){
|
||||||
Drawable d = getDrawAble(name);
|
removeToDrawWithoutUpdate(name);
|
||||||
if(d != null)
|
|
||||||
toDraw.remove(d);
|
|
||||||
contentChanged=true;
|
contentChanged=true;
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -236,6 +257,7 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* retourne une carte au coodonés donné
|
* retourne une carte au coodonés donné
|
||||||
|
* MAIS ne met pas ajour le rendu
|
||||||
* @param x coordoné en x
|
* @param x coordoné en x
|
||||||
* @param y coodoné en y
|
* @param y coodoné en y
|
||||||
* @return
|
* @return
|
||||||
@@ -243,15 +265,15 @@ public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
public DrawableCard getCardOn(float x, float y) {
|
public DrawableCard getCardOn(float x, float y) {
|
||||||
for(Drawable d : toDraw)
|
for(Drawable d : toDraw)
|
||||||
{
|
{
|
||||||
if(d instanceof DrawableCard)
|
//on n'a pas d'objet non card a deplacer
|
||||||
|
//si on venais a en avoir besoin crée une interface draggable s'avererais utile
|
||||||
|
if(d instanceof DrawableCard && d.isDraggable())
|
||||||
{
|
{
|
||||||
DrawableCard card = ((DrawableCard)d);
|
DrawableCard card = ((DrawableCard)d);
|
||||||
if(x >= card.getX() && x <= card.getX()+card.getCardWith())
|
if(x >= card.getX() && x <= card.getX()+card.getCardWith())
|
||||||
{
|
{
|
||||||
if(y >= card.getY() && y <= card.getY()+card.getCardHeight())
|
if(y >= card.getY() && y <= card.getY()+card.getCardHeight())
|
||||||
{
|
{
|
||||||
//on considére que si on prend la carte c'est pour changer ses valeurs
|
|
||||||
contentChanged=true;
|
|
||||||
return card;
|
return card;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user