-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathShooting.java
executable file
·134 lines (111 loc) · 3.79 KB
/
Shooting.java
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
// Shooting.java
// Henry Hu, Nafis Molla
// May 14, 2019
// ICS4U
// Input class to calculate power and add Projectiles to the game. Main game extends Screen,
// this class extends ApplicationAdapter for event based input
package com.mygdx.game;
import com.badlogic.gdx.ApplicationAdapter;
import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input;
import com.badlogic.gdx.InputProcessor;
import com.badlogic.gdx.graphics.glutils.ShapeRenderer;
import java.util.*;
public class Shooting extends ApplicationAdapter implements InputProcessor {
private static float power = 0;//amount of power charged up for each shot
private static int up_or_down=0;//whether the power increases or decreases
private static final int UP = 1;//directions
private static final int DOWN = - 1;
private int mx,my;
private Player player;
private ShapeRenderer sr;
private ArrayList<Projectile> shots;
public Shooting(ArrayList<Projectile> proj, Player p1){
shots = proj;
player = p1;
sr = new ShapeRenderer();
}
@Override
public void create(){
Gdx.input.setInputProcessor(this);
}
@Override
public void render(){
mx = Gdx.input.getX();
my = Gdx.input.getY();
if (Gdx.input.isButtonPressed(Input.Buttons.LEFT)){ //clicking the left mouse button
powerCalc(); //calculate power
}
for (int i=0; i<shots.size(); i++){ //move the Projectiles
shots.get(i).shoot();
}
}
@Override
public void dispose(){
}
private void powerCalc(){ //calculates power for the Projectile to use
if (power<=0){ //once the power is at a minimum, it goes up
up_or_down = UP;
}
else if (power>=30){ //once the power is at a maximum, it goes down
up_or_down = DOWN;
}
if (power<=20){
power += up_or_down;
}
else if (power<=25){
power += up_or_down * 2;
}
else if (power<=34) {
power += up_or_down * 3;
}
//if power is lower than it will take a longer amount of time for it to increase
//if it's higher, than it will increase faster
}
public float getPower(){ return power; }
public ArrayList<Projectile> getShots(){ return shots; } //the Projectile ArrayList
@Override
public boolean scrolled(int amount) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean mouseMoved(int screenX, int screenY) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean touchDragged(int screenX, int screenY, int pointer) {
// TODO Auto-generated method stub
return false;
}
@Override
// Mouse up/touch released
public boolean touchUp(int screenX, int screenY, int pointer, int button) {
if (button==Input.Buttons.LEFT) { //touch up of the left mouse button
shots.add(new Projectile(mx, my, player.getX()+Player.center_x, player.getY()+Player.center_y, power));
//projectile based off mouse, player centre and power level
}
power = 0;
return false;
}
@Override
// Mouse down/touched
public boolean touchDown(int screenX, int screenY, int pointer, int button) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyTyped(char character) {
// TODO Auto-generated method stub
return false;
}
@Override
public boolean keyUp(int keycode) {
return false;
}
@Override
public boolean keyDown(int keycode) {
return false;
}
}