Skip to content

Commit 94bbf14

Browse files
committed
Nuevos ejemplos
1 parent 2690b07 commit 94bbf14

File tree

17 files changed

+1449
-0
lines changed

17 files changed

+1449
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package org.sfsoft.jfighter2dx.characters;
2+
3+
import org.sfsoft.jfighter2dx.managers.ResourceManager;
4+
import org.sfsoft.jfighter2dx.util.Constants;
5+
6+
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
7+
import com.badlogic.gdx.math.Rectangle;
8+
9+
/**
10+
* Tipo de enemigo de grandes dimensiones y mayor resistencia
11+
* @author Santiago Faci
12+
* @version 1.0
13+
*
14+
*/
15+
public class BigEnemy extends Enemy {
16+
17+
public BigEnemy(float x, float y, float speed) {
18+
super(x, y, speed);
19+
20+
animation = ResourceManager.getAnimation("big_enemy");
21+
setRect(new Rectangle(x, y, Constants.ENEMY_WIDTH * 2, Constants.ENEMY_HEIGHT * 2));
22+
setValue(10);
23+
setLives(4);
24+
}
25+
26+
@Override
27+
public void update(float dt) {
28+
29+
super.update(dt);
30+
31+
setX(getX() + getSpeed() * dt);
32+
setRectX(getX());
33+
}
34+
35+
@Override
36+
public void draw(SpriteBatch batch) {
37+
batch.draw(currentFrame, getX(), getY());
38+
}
39+
}

Characters/characters/Block.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.sfsoft.jfighter2dx.characters;
2+
3+
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
4+
5+
/**
6+
* Clase base para cualquier elemento del juego que sea un bloque no animado
7+
* @author Santiago Faci
8+
* @version 1.0
9+
*
10+
*/
11+
public class Block extends Character {
12+
// FIXME
13+
// private SpriteSheet spriteSheet;
14+
private int width;
15+
private int height;
16+
17+
public Block(float x, float y, int width, int height) {
18+
super(x, y);
19+
// FIXME
20+
// this.spriteSheet = ResourceManager.getSpriteSheet("blocks");
21+
this.width = width;
22+
this.height = height;
23+
}
24+
25+
public void update(float dt) {
26+
27+
setX(getX() + getSpeed() * dt);
28+
}
29+
30+
@Override
31+
public void draw(SpriteBatch batch) {
32+
33+
for (int i = 0; i < width; i++) {
34+
for (int j = 0; j < height; j++) {
35+
// FIXME
36+
/*
37+
spriteSheet.getSprite(14, 5).draw(x + BLOCK_WIDTH * i, y - BLOCK_HEIGHT * (j + 1));*/
38+
}
39+
}
40+
41+
}
42+
43+
44+
}

Characters/characters/Bullet.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package org.sfsoft.jfighter2dx.characters;
2+
3+
import com.badlogic.gdx.graphics.Texture;
4+
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
5+
6+
/**
7+
* Es la clase base para cualquier tipo de proyectil en el juego
8+
* @author Santiago Faci
9+
* @version 1.0
10+
*
11+
*/
12+
public abstract class Bullet extends Character {
13+
14+
protected Texture texture;
15+
16+
public Bullet(float x, float y, float speed) {
17+
super(x, y, speed);
18+
}
19+
20+
public void draw(SpriteBatch batch) {
21+
22+
batch.draw(texture, getX(), getY());
23+
}
24+
25+
public abstract void update(float dt);
26+
27+
}
Lines changed: 164 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,164 @@
1+
package org.sfsoft.jfighter2dx.characters;
2+
3+
import com.badlogic.gdx.graphics.g2d.Animation;
4+
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
5+
import com.badlogic.gdx.graphics.g2d.TextureRegion;
6+
import com.badlogic.gdx.math.Rectangle;
7+
import com.badlogic.gdx.utils.Disposable;
8+
9+
/**
10+
* Representa cualquier elemento animado (juegador o NPC) del juego
11+
* @author Santiago Faci
12+
*
13+
*/
14+
public abstract class Character implements Disposable {
15+
16+
// Velocidad del personaje
17+
private float speed;
18+
// Velocidad de los proyectiles del personaje
19+
private float bulletSpeed;
20+
// Ratio de disparo
21+
private float bulletRate;
22+
// Puntos (si procede)
23+
private int points;
24+
// Vidas
25+
private int lives;
26+
27+
// Posición y rectángulo representados por el personaje
28+
protected float x;
29+
protected float y;
30+
private Rectangle rect;
31+
32+
// Animación del personaje
33+
protected Animation animation;
34+
protected float stateTime;
35+
protected TextureRegion currentFrame;
36+
37+
// Dirección de salida del personaje
38+
public enum Direction {
39+
LEFT, RIGHT
40+
}
41+
42+
public Character(float x, float y) {
43+
44+
// Default values
45+
speed = 200f;
46+
bulletSpeed = 400f;
47+
bulletRate = 0.2f;
48+
points = 100;
49+
lives = 1;
50+
51+
this.x = x;
52+
this.y = y;
53+
}
54+
55+
public Character(float x, float y, float speed) {
56+
57+
// Default values
58+
bulletSpeed = 400f;
59+
bulletRate = 0.2f;
60+
points = 100;
61+
lives = 1;
62+
63+
this.speed = speed;
64+
this.x = x;
65+
this.y = y;
66+
}
67+
68+
public float getSpeed() {
69+
return speed;
70+
}
71+
72+
public void setSpeed(float speed) {
73+
this.speed = speed;
74+
}
75+
76+
public float getBulletSpeed() {
77+
return bulletSpeed;
78+
}
79+
80+
public void setBulletSpeed(float bulletSpeed) {
81+
this.bulletSpeed = bulletSpeed;
82+
}
83+
84+
public float getBulletRate() {
85+
return bulletRate;
86+
}
87+
88+
public void setBulletRate(float bulletRate) {
89+
this.bulletRate = bulletRate;
90+
}
91+
92+
public int getPoints() {
93+
return points;
94+
}
95+
96+
public void setPoints(int points) {
97+
this.points = points;
98+
}
99+
100+
public int getLives() {
101+
return lives;
102+
}
103+
104+
public void setLives(int lives) {
105+
this.lives = lives;
106+
}
107+
108+
public float getX() {
109+
return x;
110+
}
111+
112+
public void setX(float x) {
113+
this.x = x;
114+
}
115+
116+
public float getY() {
117+
return y;
118+
}
119+
120+
public void setY(float y) {
121+
this.y = y;
122+
}
123+
124+
public Rectangle getRect() {
125+
return rect;
126+
}
127+
128+
public void setRect(Rectangle rect) {
129+
this.rect = rect;
130+
}
131+
132+
public float getRectX() {
133+
return rect.getX();
134+
}
135+
136+
public void setRectX(float x) {
137+
rect.setX(x);
138+
}
139+
140+
public float getRectY() {
141+
return rect.getY();
142+
}
143+
144+
public void setRectY(float y) {
145+
rect.setY(y);
146+
}
147+
148+
// Recibe un impacto
149+
public void hit() {
150+
lives--;
151+
}
152+
153+
// Dibuja en pantalla el personaje
154+
public abstract void draw(SpriteBatch batch);
155+
156+
public void die() {}
157+
158+
@Override
159+
public void dispose() {
160+
161+
rect = null;
162+
animation = null;
163+
}
164+
}

Characters/characters/Enemy.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package org.sfsoft.jfighter2dx.characters;
2+
3+
import com.badlogic.gdx.Gdx;
4+
5+
/**
6+
* Clase base de todos los enemigos del personaje en el juego
7+
* @author Santiago Faci
8+
*
9+
*/
10+
public abstract class Enemy extends Character {
11+
12+
public enum EnemyType {
13+
SMALL_ENEMY, STONE, SHOOTER_ENEMY, PURSUER_ENEMY, BIG_ENEMY, STATIC_SHOOTER_ENEMY
14+
}
15+
16+
// Valor en puntos del enemigo (al ser derribado por el jugador)
17+
private int value;
18+
19+
public Enemy(float x, float y) {
20+
super(x, y);
21+
}
22+
23+
public Enemy(float x, float y, float speed) {
24+
super(x, y, speed);
25+
}
26+
27+
public int getValue() {
28+
return value;
29+
}
30+
31+
public void setValue(int value) {
32+
this.value = value;
33+
}
34+
35+
/**
36+
* Calcula cuál será el movimiento del enemigo y lo desplaza
37+
* @param dt
38+
*/
39+
public void update(float dt) {
40+
41+
stateTime += Gdx.graphics.getDeltaTime();
42+
currentFrame = animation.getKeyFrame(stateTime, true);
43+
}
44+
}

Characters/characters/Missile.java

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package org.sfsoft.jfighter2dx.characters;
2+
3+
import org.sfsoft.jfighter2dx.managers.ResourceManager;
4+
import org.sfsoft.jfighter2dx.util.Constants;
5+
6+
import com.badlogic.gdx.Gdx;
7+
import com.badlogic.gdx.graphics.g2d.Animation;
8+
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
9+
import com.badlogic.gdx.math.Rectangle;
10+
11+
/**
12+
* Clase que representa a los mísiles que lanza la nave del personaje
13+
* @author Santiago Faci
14+
* @version 1.0
15+
*
16+
*/
17+
public class Missile extends Bullet {
18+
19+
private Animation animation;
20+
private float acceleration;
21+
22+
public Missile(float x, float y, float speed) {
23+
super(x, y, speed);
24+
25+
animation = ResourceManager.getAnimation("missile");
26+
acceleration = 0;
27+
setRect(new Rectangle(x, y, Constants.MISSILE_WIDTH, Constants.MISSILE_HEIGHT));
28+
}
29+
30+
@Override
31+
public void draw(SpriteBatch batch) {
32+
33+
if (currentFrame != null)
34+
batch.draw(currentFrame, getX(), getY());
35+
}
36+
37+
@Override
38+
public void update(float dt) {
39+
40+
stateTime += Gdx.graphics.getDeltaTime();
41+
currentFrame = animation.getKeyFrame(stateTime, true);
42+
43+
setX(getX() + getSpeed() * dt);
44+
setY(getY() - getSpeed() * acceleration * dt);
45+
46+
setRectX(getX());
47+
setRectY(getY());
48+
49+
if (acceleration < 5f)
50+
acceleration += 0.05f;
51+
}
52+
}

0 commit comments

Comments
 (0)