amelioration du moteur + ajout de DrawableCard pour simplifer la creation de carte + correction du support de texture + correction du support de rectangle
This commit is contained in:
@@ -9,7 +9,7 @@
|
|||||||
android:roundIcon="@mipmap/ic_launcher_round"
|
android:roundIcon="@mipmap/ic_launcher_round"
|
||||||
android:supportsRtl="true"
|
android:supportsRtl="true"
|
||||||
android:theme="@style/AppTheme">
|
android:theme="@style/AppTheme">
|
||||||
<activity android:name=".MainActivity">
|
<activity android:name=".GameActivity">
|
||||||
<intent-filter>
|
<intent-filter>
|
||||||
<action android:name="android.intent.action.MAIN" />
|
<action android:name="android.intent.action.MAIN" />
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +0,0 @@
|
|||||||
package com.iutlaval.myapplication;
|
|
||||||
|
|
||||||
public class DrawableNotFoundException extends Exception{
|
|
||||||
}
|
|
||||||
@@ -0,0 +1,41 @@
|
|||||||
|
package com.iutlaval.myapplication.Game;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
|
import com.iutlaval.myapplication.Game.Player.Player;
|
||||||
|
import com.iutlaval.myapplication.Game.Player.PlayerBot;
|
||||||
|
import com.iutlaval.myapplication.Game.Player.PlayerOnlineAdversary;
|
||||||
|
import com.iutlaval.myapplication.Game.Player.PlayerLocal;
|
||||||
|
import com.iutlaval.myapplication.GameActivity;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public class Board {
|
||||||
|
private static final int MAX_CARD_ON_BOARD=10;
|
||||||
|
private List<Card> AdvCardsOnBoard;
|
||||||
|
private List<Card> PlayerCardsOnBoard;
|
||||||
|
private PlayerLocal player1;
|
||||||
|
private Player player2;
|
||||||
|
|
||||||
|
public Board()
|
||||||
|
{
|
||||||
|
AdvCardsOnBoard = new ArrayList<>();
|
||||||
|
PlayerCardsOnBoard = new ArrayList<>();
|
||||||
|
player1 = new PlayerLocal();
|
||||||
|
|
||||||
|
if(GameActivity.isMultiplayer())
|
||||||
|
{
|
||||||
|
player2 = new PlayerOnlineAdversary();
|
||||||
|
}else{
|
||||||
|
player2 = new PlayerBot();
|
||||||
|
}
|
||||||
|
|
||||||
|
//TODO fill decks
|
||||||
|
if(GameActivity.isHosting())
|
||||||
|
{
|
||||||
|
|
||||||
|
}else{
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,69 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Cards;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.util.Log;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Board;
|
||||||
|
import com.iutlaval.myapplication.R;
|
||||||
|
|
||||||
|
public abstract class Card {
|
||||||
|
private int health;
|
||||||
|
private int attack;
|
||||||
|
|
||||||
|
private static Bitmap frameBitmap = null;
|
||||||
|
|
||||||
|
public void onCardAttack(Board board){}
|
||||||
|
|
||||||
|
public void onCardPlayed(Board board){}
|
||||||
|
|
||||||
|
public void onCardDeath(Board board){}
|
||||||
|
|
||||||
|
public void onTurnBegin(Board board){}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* SURTOUT NE PAS @OVERRIDE
|
||||||
|
* si vous voulez modifier le cadre changer getFrameTexture()
|
||||||
|
* @param c context
|
||||||
|
* @return bitmap
|
||||||
|
*/
|
||||||
|
public Bitmap getFrameBitmap(Context c)
|
||||||
|
{
|
||||||
|
//TODO add a frame
|
||||||
|
if(frameBitmap == null) {
|
||||||
|
frameBitmap=BitmapFactory.decodeResource(c.getResources(), R.drawable.cadre_carte);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(getFrameTexture() == R.drawable.cadre_carte)
|
||||||
|
{
|
||||||
|
return frameBitmap;
|
||||||
|
}else{
|
||||||
|
return BitmapFactory.decodeResource(c.getResources(),getFrameTexture());
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getFrameTexture()
|
||||||
|
{
|
||||||
|
return R.drawable.cadre_carte;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public abstract int getCardPicture();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* retourne la culeur de la carte
|
||||||
|
* la couleur s'affiche comme un filtre sur la carte
|
||||||
|
* /!\ attention a l'opacite /!\ le format n'est PAS rgba MAIS argb
|
||||||
|
* #AARRGGBB
|
||||||
|
* je recomander une opaciter en 44 et 70
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public String getColor()
|
||||||
|
{
|
||||||
|
return "#00000000";
|
||||||
|
}
|
||||||
|
//TODO
|
||||||
|
}
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Cards;
|
||||||
|
|
||||||
|
import android.graphics.Color;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.R;
|
||||||
|
|
||||||
|
public class DemoCard extends Card{
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getCardPicture() {
|
||||||
|
return R.drawable.guerrier_nul;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//#AARRGGBB
|
||||||
|
@Override
|
||||||
|
public String getColor() {
|
||||||
|
return "#70FF0000";
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,49 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Player;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Random;
|
||||||
|
|
||||||
|
public abstract class Player {
|
||||||
|
private static final int MAX_HAND_SIZE = 10;
|
||||||
|
|
||||||
|
private List<Card> deck;
|
||||||
|
private List<Card> hand;
|
||||||
|
private int hp = 100;
|
||||||
|
|
||||||
|
|
||||||
|
public Player(){
|
||||||
|
deck=new ArrayList<>();
|
||||||
|
hand=new ArrayList<>();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void shuffle()
|
||||||
|
{
|
||||||
|
Collections.shuffle(deck);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cette fonction ajoute un carte dans la main de l'utilisateur
|
||||||
|
*/
|
||||||
|
public void pickCard()
|
||||||
|
{
|
||||||
|
if(!deck.isEmpty()) {
|
||||||
|
if (hand.size() >= MAX_HAND_SIZE) {
|
||||||
|
deck.remove(0);
|
||||||
|
} else {
|
||||||
|
hand.add(deck.remove(0));
|
||||||
|
}
|
||||||
|
}else{
|
||||||
|
getHurt(2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void getHurt(int dmg)
|
||||||
|
{
|
||||||
|
hp -= dmg;
|
||||||
|
//TODO death trigger
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Player;
|
||||||
|
|
||||||
|
public class PlayerBot extends Player{
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Player;
|
||||||
|
|
||||||
|
public class PlayerLocal extends Player{
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.iutlaval.myapplication.Game.Player;
|
||||||
|
|
||||||
|
public class PlayerOnlineAdversary extends Player{
|
||||||
|
}
|
||||||
@@ -0,0 +1,109 @@
|
|||||||
|
package com.iutlaval.myapplication;
|
||||||
|
|
||||||
|
//N'oubliez pas de déclarer le bon package dans lequel se trouve le fichier !
|
||||||
|
|
||||||
|
import android.app.Activity;
|
||||||
|
import android.content.pm.ActivityInfo;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Point;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
import android.os.Bundle;
|
||||||
|
import android.view.Display;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.DemoCard;
|
||||||
|
import com.iutlaval.myapplication.Video.Drawable;
|
||||||
|
import com.iutlaval.myapplication.Video.DrawableCard;
|
||||||
|
import com.iutlaval.myapplication.Video.FpsTime;
|
||||||
|
import com.iutlaval.myapplication.Video.Rectangle;
|
||||||
|
import com.iutlaval.myapplication.Video.Renderer;
|
||||||
|
|
||||||
|
public class GameActivity extends Activity {
|
||||||
|
|
||||||
|
public static int screenWidth=0;
|
||||||
|
public static int screenHeight=0;
|
||||||
|
public static boolean bilinearFiltering = true;
|
||||||
|
|
||||||
|
public static boolean isMultiplayer() {
|
||||||
|
return false;//TODO implement it
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isHosting() {
|
||||||
|
return false;//TODO implement it
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
|
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
||||||
|
Display display = getWindowManager().getDefaultDisplay();
|
||||||
|
FpsTime.init(display);
|
||||||
|
|
||||||
|
Renderer v = new Renderer(getBaseContext());
|
||||||
|
|
||||||
|
//return portrait mode resolution so we need to flip them
|
||||||
|
Point size = new Point();
|
||||||
|
display.getSize(size);
|
||||||
|
if(size.y > size.x)
|
||||||
|
{
|
||||||
|
screenWidth = size.y;
|
||||||
|
screenHeight = size.x;
|
||||||
|
}else{
|
||||||
|
screenWidth = size.x;
|
||||||
|
screenHeight = size.y;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.debug_card);
|
||||||
|
|
||||||
|
try {
|
||||||
|
v.addToDraw(new Drawable(new Rectangle(0,0,100,100),"background",Color.BLUE));
|
||||||
|
v.addToDraw(new Drawable(bm,0.0F,0.0F,"running",8F,16F));
|
||||||
|
v.addToDraw(new DrawableCard(new DemoCard(),0.0F,0.0F,"card2",this));
|
||||||
|
} catch (InvalidDataException e) {
|
||||||
|
//cette erreur est lance si un carre est invalid
|
||||||
|
System.err.println(e.getDetail());
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
|
||||||
|
Thread t = new MainThread(v);
|
||||||
|
t.start();
|
||||||
|
|
||||||
|
setContentView(v);
|
||||||
|
}
|
||||||
|
|
||||||
|
private class MainThread extends Thread
|
||||||
|
{
|
||||||
|
Renderer view;
|
||||||
|
public MainThread(Renderer view)
|
||||||
|
{
|
||||||
|
super();
|
||||||
|
this.view=view;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
int i=0;
|
||||||
|
int increm = 1;
|
||||||
|
while(true)
|
||||||
|
{
|
||||||
|
if(i < 100)
|
||||||
|
{
|
||||||
|
i+=increm;
|
||||||
|
}else{
|
||||||
|
increm=-increm;
|
||||||
|
i+=increm;
|
||||||
|
}
|
||||||
|
if(i==0)increm=-increm;
|
||||||
|
|
||||||
|
//TODO get x,y coordinate form name
|
||||||
|
view.moveToDraw(i,i,"running");
|
||||||
|
FpsTime.waitFrameTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
@@ -1,16 +1,17 @@
|
|||||||
package com.iutlaval.myapplication;
|
package com.iutlaval.myapplication;
|
||||||
|
|
||||||
import android.graphics.Rect;
|
|
||||||
|
import com.iutlaval.myapplication.Video.Rectangle;
|
||||||
|
|
||||||
public class InvalidDataException extends Throwable {
|
public class InvalidDataException extends Throwable {
|
||||||
private String name;
|
private String name;
|
||||||
private float x;
|
private float x;
|
||||||
private float y;
|
private float y;
|
||||||
|
|
||||||
public InvalidDataException(String name, Rect rectangle)
|
public InvalidDataException(String name, Rectangle rectangle)
|
||||||
{
|
{
|
||||||
x = rectangle.width();
|
x = rectangle.getWidth();
|
||||||
y = rectangle.height();
|
y = rectangle.getHeight();
|
||||||
this.name=name;
|
this.name=name;
|
||||||
}
|
}
|
||||||
public InvalidDataException(String name,float x,float y)
|
public InvalidDataException(String name,float x,float y)
|
||||||
|
|||||||
@@ -1,64 +0,0 @@
|
|||||||
package com.iutlaval.myapplication;
|
|
||||||
|
|
||||||
//N'oubliez pas de déclarer le bon package dans lequel se trouve le fichier !
|
|
||||||
|
|
||||||
import android.app.Activity;
|
|
||||||
import android.content.pm.ActivityInfo;
|
|
||||||
import android.graphics.Bitmap;
|
|
||||||
import android.graphics.BitmapFactory;
|
|
||||||
import android.graphics.Canvas;
|
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
|
||||||
import android.graphics.Point;
|
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.os.Bundle;
|
|
||||||
import android.view.Display;
|
|
||||||
import android.view.SurfaceHolder;
|
|
||||||
import android.view.SurfaceView;
|
|
||||||
import android.view.View;
|
|
||||||
import android.view.Window;
|
|
||||||
import android.widget.TextView;
|
|
||||||
|
|
||||||
public class MainActivity extends Activity {
|
|
||||||
|
|
||||||
public static int screenWidth=0;
|
|
||||||
public static int screenHeight=0;
|
|
||||||
public static boolean bilinearFiltering = true;
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
|
||||||
super.onCreate(savedInstanceState);
|
|
||||||
|
|
||||||
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
|
|
||||||
Display display = getWindowManager().getDefaultDisplay();
|
|
||||||
|
|
||||||
|
|
||||||
CanevasView v = new CanevasView(getBaseContext());
|
|
||||||
|
|
||||||
//return portrait mode resolution so we need to flip them
|
|
||||||
Point size = new Point();
|
|
||||||
display.getSize(size);
|
|
||||||
if(size.y > size.x)
|
|
||||||
{
|
|
||||||
screenWidth = size.y;
|
|
||||||
screenHeight = size.x;
|
|
||||||
}else{
|
|
||||||
screenWidth = size.x;
|
|
||||||
screenHeight = size.y;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
Bitmap bm = BitmapFactory.decodeResource(getResources(), R.drawable.debug_card);
|
|
||||||
|
|
||||||
try {
|
|
||||||
v.addToDraw(new Drawable(new Rect(0,0,screenWidth,screenHeight),"background",Color.BLUE));
|
|
||||||
v.addToDraw(new Drawable(bm,0.0F,00.0F,"Card1",50F,50F));
|
|
||||||
} catch (InvalidDataException e) {
|
|
||||||
//cette erreur est lance si un carre est invalid
|
|
||||||
System.err.println(e.getDetail());
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
|
|
||||||
setContentView(v);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
+26
-17
@@ -1,12 +1,14 @@
|
|||||||
package com.iutlaval.myapplication;
|
package com.iutlaval.myapplication.Video;
|
||||||
|
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
import android.util.Log;
|
||||||
|
|
||||||
import java.util.Objects;
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.GameActivity;
|
||||||
|
import com.iutlaval.myapplication.InvalidDataException;
|
||||||
|
|
||||||
public class Drawable {
|
public class Drawable {
|
||||||
|
|
||||||
@@ -20,7 +22,7 @@ public class Drawable {
|
|||||||
* @param y coordoné y comrpis entre 0 et 100
|
* @param y coordoné y comrpis entre 0 et 100
|
||||||
* @param name nom du drawable agit comme un identifiant mais doit être unique
|
* @param name nom du drawable agit comme un identifiant mais doit être unique
|
||||||
*/
|
*/
|
||||||
private Drawable(float x,float y,String name)
|
protected Drawable(float x,float y,String name)
|
||||||
{
|
{
|
||||||
this.x=x;
|
this.x=x;
|
||||||
this.y=y;
|
this.y=y;
|
||||||
@@ -52,11 +54,11 @@ public class Drawable {
|
|||||||
*
|
*
|
||||||
* TODO : echelle dynamique avec l'ecran
|
* TODO : echelle dynamique avec l'ecran
|
||||||
*/
|
*/
|
||||||
public Drawable(Bitmap bitmap,float x_pos,float y_pos,String name,float x_size,float y_size) throws InvalidDataException {
|
public Drawable(@NonNull Bitmap bitmap, float x_pos, float y_pos, String name, float x_size, float y_size) throws InvalidDataException {
|
||||||
this(x_pos,y_pos,name);
|
this(x_pos,y_pos,name);
|
||||||
|
|
||||||
float x_scaled_size = x_size*MainActivity.screenWidth/100;
|
float x_scaled_size = x_size* GameActivity.screenWidth/100;
|
||||||
float y_scaled_size = y_size*MainActivity.screenHeight/100;
|
float y_scaled_size = y_size* GameActivity.screenHeight/100;
|
||||||
|
|
||||||
System.out.println(x_scaled_size + " y: " + y_scaled_size);
|
System.out.println(x_scaled_size + " y: " + y_scaled_size);
|
||||||
System.out.println(y_size);
|
System.out.println(y_size);
|
||||||
@@ -66,8 +68,8 @@ public class Drawable {
|
|||||||
throw new InvalidDataException(name,x_scaled_size,y_scaled_size);
|
throw new InvalidDataException(name,x_scaled_size,y_scaled_size);
|
||||||
}
|
}
|
||||||
|
|
||||||
Bitmap scaledBitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size,MainActivity.bilinearFiltering);
|
this.bitmap = Bitmap.createScaledBitmap(bitmap, (int)x_scaled_size, (int)y_scaled_size, GameActivity.bilinearFiltering);
|
||||||
this.bitmap=scaledBitmap;
|
Log.i("loul",""+this.bitmap.getWidth());
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -80,13 +82,15 @@ public class Drawable {
|
|||||||
* @param color couleur du rectangle
|
* @param color couleur du rectangle
|
||||||
*/
|
*/
|
||||||
@Deprecated
|
@Deprecated
|
||||||
public Drawable(Rect rectangle, String name, int color) throws InvalidDataException {
|
public Drawable(Rectangle rectangle, String name, int color) throws InvalidDataException {
|
||||||
if(rectangle.height() <= 0 || rectangle.width() <=0)throw new InvalidDataException(name,rectangle);
|
if(rectangle.getHeight() <= 0 || rectangle.getWidth() <=0)throw new InvalidDataException(name,rectangle);
|
||||||
|
|
||||||
Bitmap bitmap = Bitmap.createBitmap(rectangle.width(),rectangle.height(), Bitmap.Config.ARGB_8888);
|
rectangle.scaleRectangleToScreen();
|
||||||
|
|
||||||
|
Bitmap bitmap = Bitmap.createBitmap((int)rectangle.getWidth(),(int)rectangle.getHeight(), Bitmap.Config.ARGB_8888);
|
||||||
|
|
||||||
//on crée un canevas pour interagir avec la bitmap
|
//on crée un canevas pour interagir avec la bitmap
|
||||||
Canvas c = new Canvas(bitmap);
|
RectangleCanevas c = new RectangleCanevas(bitmap);
|
||||||
Paint p = new Paint();
|
Paint p = new Paint();
|
||||||
|
|
||||||
p.setColor(color);
|
p.setColor(color);
|
||||||
@@ -96,14 +100,14 @@ public class Drawable {
|
|||||||
|
|
||||||
this.bitmap=bitmap;
|
this.bitmap=bitmap;
|
||||||
this.name=name;
|
this.name=name;
|
||||||
this.x=rectangle.left;
|
this.x=rectangle.getPositionX();
|
||||||
this.y=rectangle.top;
|
this.y=rectangle.getPositionY();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void drawOn(Canvas c, Paint p)
|
public void drawOn(Canvas c, Paint p)
|
||||||
{
|
{
|
||||||
//drawings
|
//drawings
|
||||||
c.drawBitmap(bitmap,x*MainActivity.screenWidth/100,y*MainActivity.screenHeight/100,p);
|
c.drawBitmap(getBitmap(),x* GameActivity.screenWidth/100,y* GameActivity.screenHeight/100,p);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bitmap getBitmap() {
|
public Bitmap getBitmap() {
|
||||||
@@ -135,4 +139,9 @@ public class Drawable {
|
|||||||
this.x=x;
|
this.x=x;
|
||||||
this.y=y;
|
this.y=y;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* cette fonction est appeler quand le drawable est retirer de la liste toDraw
|
||||||
|
*/
|
||||||
|
public void onDeletion(Renderer r){}
|
||||||
}
|
}
|
||||||
@@ -0,0 +1,42 @@
|
|||||||
|
package com.iutlaval.myapplication.Video;
|
||||||
|
|
||||||
|
import android.content.Context;
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.BitmapFactory;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Color;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.Game.Cards.Card;
|
||||||
|
import com.iutlaval.myapplication.InvalidDataException;
|
||||||
|
|
||||||
|
public class DrawableCard extends Drawable{
|
||||||
|
|
||||||
|
private static final int CARD_WITH = 14;
|
||||||
|
private static final int CARD_HEIGHT = 32;
|
||||||
|
|
||||||
|
private String color;
|
||||||
|
|
||||||
|
private Drawable OpacityRectangleDrawable;
|
||||||
|
private Drawable PictureDrawable;
|
||||||
|
|
||||||
|
public DrawableCard(Card c, float x, float y, String name, Context context) throws InvalidDataException {
|
||||||
|
super(c.getFrameBitmap(context),x,y,name,CARD_WITH,CARD_HEIGHT);
|
||||||
|
|
||||||
|
color = c.getColor();//CARD_WITH+x
|
||||||
|
Rectangle cardRect = new Rectangle(x,y,(float)(CARD_WITH+x),(float)(CARD_HEIGHT+x));
|
||||||
|
OpacityRectangleDrawable = new Drawable(cardRect,toString()+"Opacity", Color.parseColor(c.getColor()));
|
||||||
|
|
||||||
|
Bitmap pictureBitmap = BitmapFactory.decodeResource(context.getResources(),c.getCardPicture());
|
||||||
|
PictureDrawable = new Drawable(pictureBitmap,getX()+1.1F,getY()+2.5F,toString()+"Picture",CARD_WITH-2.4F,CARD_HEIGHT/2 - 4);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void drawOn(Canvas c, Paint p) {
|
||||||
|
//draw the frame
|
||||||
|
super.drawOn(c, p);
|
||||||
|
OpacityRectangleDrawable.drawOn(c,p);
|
||||||
|
PictureDrawable.drawOn(c,p);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
package com.iutlaval.myapplication.Video;
|
||||||
|
|
||||||
|
public class DrawableNotFoundException extends RuntimeException{
|
||||||
|
}
|
||||||
@@ -0,0 +1,19 @@
|
|||||||
|
package com.iutlaval.myapplication.Video;
|
||||||
|
|
||||||
|
import android.view.Display;
|
||||||
|
|
||||||
|
public class FpsTime {
|
||||||
|
private static long frametime;
|
||||||
|
|
||||||
|
public static void init(Display d)
|
||||||
|
{
|
||||||
|
float fps = d.getRefreshRate();
|
||||||
|
frametime = (long)(1.0F/fps*1000);
|
||||||
|
}
|
||||||
|
|
||||||
|
public static void waitFrameTime(){
|
||||||
|
try {
|
||||||
|
Thread.sleep((frametime));
|
||||||
|
} catch (InterruptedException e) {}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
package com.iutlaval.myapplication.Video;
|
||||||
|
|
||||||
|
import com.iutlaval.myapplication.GameActivity;
|
||||||
|
|
||||||
|
public class Rectangle {
|
||||||
|
|
||||||
|
float positionX,positionY,width,height;
|
||||||
|
public Rectangle(float positionX,float positionY,float width,float height)
|
||||||
|
{
|
||||||
|
set(positionX,positionY,width,height);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void set(float positionX,float positionY,float width,float height)
|
||||||
|
{
|
||||||
|
this.positionX=positionX;
|
||||||
|
this.positionY=positionY;
|
||||||
|
this.width=width;
|
||||||
|
this.height=height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPositionX() {
|
||||||
|
return positionX;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getPositionY() {
|
||||||
|
return positionY;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getHeight() {
|
||||||
|
return height;
|
||||||
|
}
|
||||||
|
|
||||||
|
public float getWidth() {
|
||||||
|
return width;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void scaleRectangleToScreen()
|
||||||
|
{
|
||||||
|
set(getPositionX()* GameActivity.screenWidth/100,
|
||||||
|
getPositionY()*GameActivity.screenHeight/100,
|
||||||
|
getWidth()*GameActivity.screenWidth/100,
|
||||||
|
getHeight()*GameActivity.screenHeight/100
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.iutlaval.myapplication.Video;
|
||||||
|
|
||||||
|
import android.graphics.Bitmap;
|
||||||
|
import android.graphics.Canvas;
|
||||||
|
import android.graphics.Paint;
|
||||||
|
import android.graphics.Rect;
|
||||||
|
|
||||||
|
import androidx.annotation.NonNull;
|
||||||
|
|
||||||
|
public class RectangleCanevas extends Canvas {
|
||||||
|
public RectangleCanevas(Bitmap bitmap)
|
||||||
|
{
|
||||||
|
super(bitmap);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void drawRect(@NonNull Rectangle r, @NonNull Paint paint) {
|
||||||
|
super.drawRect(r.getPositionX(),
|
||||||
|
r.getPositionY(),
|
||||||
|
r.getPositionX()+r.getWidth(),
|
||||||
|
r.getPositionY()+r.getHeight(),
|
||||||
|
paint);
|
||||||
|
}
|
||||||
|
}
|
||||||
+29
-30
@@ -1,11 +1,10 @@
|
|||||||
package com.iutlaval.myapplication;
|
package com.iutlaval.myapplication.Video;
|
||||||
|
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Color;
|
import android.graphics.Color;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Rect;
|
|
||||||
import android.view.SurfaceHolder;
|
import android.view.SurfaceHolder;
|
||||||
import android.view.SurfaceView;
|
import android.view.SurfaceView;
|
||||||
|
|
||||||
@@ -14,7 +13,7 @@ import androidx.annotation.NonNull;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
public class CanevasView extends SurfaceView implements SurfaceHolder.Callback {
|
public class Renderer extends SurfaceView implements SurfaceHolder.Callback {
|
||||||
|
|
||||||
private SurfaceHolder holder;
|
private SurfaceHolder holder;
|
||||||
private Paint p;
|
private Paint p;
|
||||||
@@ -22,9 +21,8 @@ public class CanevasView extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
|
|
||||||
|
|
||||||
private List<Drawable> toDraw;
|
private List<Drawable> toDraw;
|
||||||
private Rect fullscreen;
|
|
||||||
|
|
||||||
public CanevasView(Context context) {
|
public Renderer(Context context) {
|
||||||
super(context);
|
super(context);
|
||||||
holder = getHolder();
|
holder = getHolder();
|
||||||
holder.addCallback(this);
|
holder.addCallback(this);
|
||||||
@@ -40,7 +38,6 @@ public class CanevasView extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void surfaceCreated(@NonNull SurfaceHolder holder) {
|
public void surfaceCreated(@NonNull SurfaceHolder holder) {
|
||||||
fullscreen = holder.getSurfaceFrame();
|
|
||||||
drawingThread.start();
|
drawingThread.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,11 +87,8 @@ public class CanevasView extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//empecher d'aller plus vite que le taux de rafraichissement de l'ecran
|
//empecher d'aller plus vite que le taux de rafraichissement de l'ecran
|
||||||
//sauve de la betterie
|
//sauve de la baterie
|
||||||
try {
|
FpsTime.waitFrameTime();
|
||||||
float fps = getDisplay().getRefreshRate();
|
|
||||||
Thread.sleep((long)(1.0/fps*1000));
|
|
||||||
} catch (InterruptedException e) {}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -121,7 +115,7 @@ public class CanevasView extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
* @param y coodonné en y (-1.0 a 1.0)
|
* @param y coodonné en y (-1.0 a 1.0)
|
||||||
* @param name nom de l'element a modifier
|
* @param name nom de l'element a modifier
|
||||||
*/
|
*/
|
||||||
public void ChangeToDraw(float x,float y,String name) throws DrawableNotFoundException {
|
public void moveToDraw(float x, float y, String name) throws DrawableNotFoundException {
|
||||||
for(Drawable d : toDraw)
|
for(Drawable d : toDraw)
|
||||||
{
|
{
|
||||||
if(d.getName().equals(name))
|
if(d.getName().equals(name))
|
||||||
@@ -134,34 +128,39 @@ public class CanevasView extends SurfaceView implements SurfaceHolder.Callback {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove the element from the draw list
|
* supprime le drawable possedant le nom indique
|
||||||
* @param name the element name
|
* @param name le nom
|
||||||
*/
|
*/
|
||||||
public void removeToDraw(String name){
|
public void removeToDraw(String name){
|
||||||
Drawable toRemove = null;
|
Drawable d = getDrawAble(name);
|
||||||
for(Drawable d : toDraw)
|
if(d != null)
|
||||||
{
|
toDraw.remove(d);
|
||||||
if(d.getName().equals(name))
|
|
||||||
{
|
|
||||||
toRemove=d;
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
}
|
|
||||||
if(toRemove != null)
|
|
||||||
{
|
|
||||||
toDraw.remove(toRemove);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* remove the element from the draw list
|
* remove the element from the draw list
|
||||||
* @param toRemove the element toRemove
|
* @param toRemove the element toRemove
|
||||||
*/
|
*/
|
||||||
public void removeToDraw(Drawable toRemove){
|
public void removeToDraw(Drawable toRemove){
|
||||||
|
toRemove.onDeletion(this);
|
||||||
toDraw.remove(toRemove);
|
toDraw.remove(toRemove);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Rect getFullscreen() {
|
|
||||||
return fullscreen;
|
/**
|
||||||
|
* retourne le drawable possedant le nom indiqué
|
||||||
|
* @param name le nom du drawable
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public Drawable getDrawAble(String name){
|
||||||
|
Drawable drawable = null;
|
||||||
|
for(Drawable d : toDraw)
|
||||||
|
{
|
||||||
|
if(d.getName().equals(name))
|
||||||
|
{
|
||||||
|
drawable=d;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return drawable;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Binary file not shown.
|
After Width: | Height: | Size: 5.4 KiB |
Binary file not shown.
|
After Width: | Height: | Size: 54 KiB |
@@ -4,7 +4,7 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
tools:context=".MainActivity">
|
tools:context=".GameActivity">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
|
|||||||
Reference in New Issue
Block a user