-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase_game_1.java
More file actions
238 lines (201 loc) · 8.26 KB
/
base_game_1.java
File metadata and controls
238 lines (201 loc) · 8.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
package com.mygdx.base_game_1;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.graphics.GL20;
import com.badlogic.gdx.graphics.Texture;
import com.badlogic.gdx.graphics.g2d.Animation;
import com.badlogic.gdx.graphics.g2d.Sprite;
import com.badlogic.gdx.graphics.g2d.SpriteBatch;
import com.badlogic.gdx.graphics.g2d.TextureAtlas;
import com.badlogic.gdx.graphics.g2d.TextureRegion;
import com.badlogic.gdx.math.Vector2;
import com.badlogic.gdx.utils.ScreenUtils;
public class base_game_1 extends ApplicationAdapter {
SpriteBatch batch;
Texture img;
Sprite sprite;
Vector2 lightPosition, heavyPosition;
float moveSpeed;
Fighter fighter_one = new Fighter(1, 1, 1, 1, 1, 1);
Fighter fighter_two = new Fighter(1, 1, 1, 2, 1, 1);
private TextureAtlas lightIdleTexture, lightAttackTexture, lightRunTexture;
private TextureAtlas heavyIdleTexture, heavyAttackTexture, heavyRunTexture;
private TextureRegion lightCurrentFrame, heavyCurrentFrame;
private Animation <TextureRegion> lightBaseAnimation, heavyBaseAnimation;
private float elapsedTimeFighterOne, elapsedTimeFighterTwo = 0;
// everything here all temporary, organization of these vars settle later on
final int IDLE = 0, LEFT = 1, RIGHT = 2, DOWN = 3, UP = 4, ATTACK_LIGHT = 5;
static boolean FACING_LEFT_FIGHTER_ONE, FACING_LEFT_FIGHTER_TWO = true;
int prevActionFighterOne, prevActionFighterTwo;
int actionFighterOne, actionFighterTwo = IDLE;
@Override
public void create () {
batch = new SpriteBatch();
// Sprites can probably be initialized using spritesheets only, https://www.youtube.com/watch?v=KwnDuc08LNE
// Tentatively we just use this first
lightIdleTexture = new TextureAtlas(Gdx.files.internal("spritesheets/Light/idle.atlas"));
lightAttackTexture = new TextureAtlas(Gdx.files.internal("spritesheets/Light/attack_light.atlas"));
lightRunTexture = new TextureAtlas(Gdx.files.internal("spritesheets/Light/run.atlas"));
heavyIdleTexture = new TextureAtlas(Gdx.files.internal("spritesheets/Heavy/idle.atlas"));
heavyAttackTexture = new TextureAtlas(Gdx.files.internal("spritesheets/Heavy/attack_light.atlas"));
heavyRunTexture = new TextureAtlas(Gdx.files.internal("spritesheets/Heavy/run.atlas"));
lightPosition = new Vector2(0,0);
heavyPosition = new Vector2(10,0);
fighter_one.setX(lightPosition.x);
fighter_one.setY(lightPosition.y);
fighter_two.setX(heavyPosition.x);
fighter_two.setY(heavyPosition.y);
moveSpeed = 10f;
}
@Override
public void render () {
// Sets the character to the IDLE animation
if ((actionFighterOne == IDLE) && (prevActionFighterOne == IDLE))
{
lightBaseAnimation = new Animation(1f/10f, lightIdleTexture.getRegions());
}
if ((actionFighterTwo == IDLE) && (prevActionFighterTwo == IDLE))
{
heavyBaseAnimation = new Animation(1f/10f, heavyIdleTexture.getRegions());
}
prevActionFighterOne = actionFighterOne;
prevActionFighterTwo = actionFighterTwo;
elapsedTimeFighterOne += Gdx.graphics.getDeltaTime();
elapsedTimeFighterTwo += Gdx.graphics.getDeltaTime();
lightCurrentFrame = lightBaseAnimation.getKeyFrame(elapsedTimeFighterOne, true);
heavyCurrentFrame = heavyBaseAnimation.getKeyFrame(elapsedTimeFighterTwo, true);
// smoll
if (FACING_LEFT_FIGHTER_ONE)
{
if (!lightCurrentFrame.isFlipX())
lightCurrentFrame.flip(true, false);
}
else
{
if (lightCurrentFrame.isFlipX())
lightCurrentFrame.flip(true, false);
}
// bik
if (FACING_LEFT_FIGHTER_TWO)
{
if (!heavyCurrentFrame.isFlipX())
heavyCurrentFrame.flip(true, false);
}
else
{
if (heavyCurrentFrame.isFlipX())
heavyCurrentFrame.flip(true, false);
}
Gdx.gl.glClearColor(0, 0, 0, 1);
Gdx.gl.glClear(GL20.GL_COLOR_BUFFER_BIT);
batch.begin();
fighter_one.draw(batch, lightCurrentFrame, lightPosition.x, lightPosition.y);
fighter_two.draw(batch, heavyCurrentFrame, heavyPosition.x, heavyPosition.y);
//batch.draw(lightCurrentFrame, lightPosition.x, lightPosition.y);
//batch.draw(heavyCurrentFrame, heavyPosition.x, heavyPosition.y);
batch.end();
// to put all of these into a function (inputs). all of these hardcoded for now
// smoll character
if(Gdx.input.isKeyPressed(Keys.A))
{
actionFighterOne = LEFT;
lightPosition.x -= moveSpeed * elapsedTimeFighterOne;
if (lightPosition.x <= 0) {
lightPosition.x = 0;
}
FACING_LEFT_FIGHTER_ONE = true;
}
else if(Gdx.input.isKeyPressed(Keys.S))
{
actionFighterOne = DOWN;
}
else if(Gdx.input.isKeyPressed(Keys.D))
{
actionFighterOne = RIGHT;
lightPosition.x += moveSpeed * elapsedTimeFighterOne;
FACING_LEFT_FIGHTER_ONE = false;
}
else if(Gdx.input.isKeyJustPressed(Keys.W))
{
actionFighterOne = UP;
}
else if(Gdx.input.isKeyJustPressed(Keys.J))
{
actionFighterOne = ATTACK_LIGHT;
}
else if(Gdx.input.isKeyJustPressed(Keys.K))
{
// Heavy attack
}
// bik chara
if(Gdx.input.isKeyPressed(Keys.LEFT))
{
actionFighterTwo = LEFT;
heavyPosition.x -= moveSpeed * elapsedTimeFighterTwo;
FACING_LEFT_FIGHTER_TWO = true;
}
else if(Gdx.input.isKeyPressed(Keys.DOWN))
{
actionFighterTwo = DOWN;
}
else if(Gdx.input.isKeyPressed(Keys.RIGHT))
{
actionFighterTwo = RIGHT;
heavyPosition.x += moveSpeed * elapsedTimeFighterTwo;
FACING_LEFT_FIGHTER_TWO = false;
}
else if(Gdx.input.isKeyJustPressed(Keys.UP))
{
actionFighterTwo = UP;
}
else if(Gdx.input.isKeyJustPressed(Keys.NUMPAD_1))
{
actionFighterTwo = ATTACK_LIGHT;
}
else if(Gdx.input.isKeyJustPressed(Keys.NUMPAD_2))
{
// Heavy attack
}
// Change the action based on the key pressed
// smoll
if(actionFighterOne != prevActionFighterOne) {
if (actionFighterOne == ATTACK_LIGHT)
lightBaseAnimation = new Animation(1f/10f, lightAttackTexture.getRegions());
else if (actionFighterOne == RIGHT)
lightBaseAnimation = new Animation(1f/10f, lightRunTexture.getRegions());
else if (actionFighterOne == LEFT)
lightBaseAnimation = new Animation(1f/10f, lightRunTexture.getRegions());
prevActionFighterOne = actionFighterOne;
}
// bik
if(actionFighterTwo != prevActionFighterTwo) {
if (actionFighterTwo == ATTACK_LIGHT)
heavyBaseAnimation = new Animation(1f/10f, heavyAttackTexture.getRegions());
else if (actionFighterTwo == RIGHT)
heavyBaseAnimation = new Animation(1f/10f, heavyRunTexture.getRegions());
else if (actionFighterTwo == LEFT)
heavyBaseAnimation = new Animation(1f/10f, heavyRunTexture.getRegions());
prevActionFighterTwo = actionFighterTwo;
}
// Once a certain animation has been completed, set back to the IDLE animation
// smoll
if (lightBaseAnimation.isAnimationFinished(elapsedTimeFighterOne))
{
prevActionFighterOne = IDLE;
actionFighterOne = IDLE;
elapsedTimeFighterOne = 0;
}
// bik
if (heavyBaseAnimation.isAnimationFinished(elapsedTimeFighterTwo))
{
prevActionFighterTwo = IDLE;
actionFighterTwo = IDLE;
elapsedTimeFighterTwo = 0;
}
fighter_one.checkCollision(lightPosition.x, lightPosition.y, heavyPosition.x, heavyPosition.y);
fighter_two.checkCollision(heavyPosition.x, heavyPosition.y, lightPosition.x, lightPosition.y);
}
}