-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayer.java
More file actions
58 lines (48 loc) · 1.25 KB
/
Player.java
File metadata and controls
58 lines (48 loc) · 1.25 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
package com.tutorial.main;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;
public class Player extends GameObject
{
Random r = new Random();
Handler handler;
public Player(int x, int y, ID id, Handler handler)
{
super(x, y, id);
this.handler = handler;
}
public Rectangle getBounds()
{
return new Rectangle((int)x, (int)y, 32, 32);
}
public void tick()
{
x += velX;
y += velY;
x = Game.clamp(x, 0, Game.WIDTH - 38);
y = Game.clamp(y, 0, Game.HEIGHT - 61);
handler.addObject(new Trail((int)x, (int)y, ID.Trail, Color.white, 32, 32, 0.25f, handler));
collision();
}
private void collision()
{
for(int i = 0; i < handler.object.size(); i ++)
{
GameObject tempObject = handler.object.get(i);
if(tempObject.getId() == ID.BasicEnemy || tempObject.getId() == ID.FastEnemy || tempObject.getId() == ID.SmartEnemy || tempObject.getId() == ID.Boss1) //if tempObject is BasicEnemy
{
if(getBounds().intersects(tempObject.getBounds()))
{
//collision code
HUD.HEALTH -= 2;
}
}
}
}
public void render(Graphics g)
{
g.setColor(Color.white);
g.fillRect((int)x, (int)y, 32, 32);
}
}