-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMenuParticle.java
More file actions
59 lines (43 loc) · 1.18 KB
/
MenuParticle.java
File metadata and controls
59 lines (43 loc) · 1.18 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
package com.tutorial.main;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.util.Random;
public class MenuParticle extends GameObject
{
private Handler handler;
Random r = new Random();
private int red = r.nextInt(255);
private int green = r.nextInt(255);
private int blue = r.nextInt(255);
private Color col;
int dir = 0;
public MenuParticle(int x, int y, ID id, Handler handler)
{
super(x, y, id);
this.handler = handler;
dir = r.nextInt(2);
velX = (r.nextInt(7 - -7) + -7);
velY = (r.nextInt(7 - -7) + -7);
if(velX == 0) velX = 1;
if(velY == 0) velY = 1;
col = new Color(r.nextInt(255), r.nextInt(255), r.nextInt(255));
}
public Rectangle getBounds()
{
return new Rectangle((int)x, (int)y, 16, 16);
}
public void tick()
{
x += velX;
y += velY;
if(y <= 0 || y >= Game.HEIGHT - 32) velY *= -1;
if(x <= 0 || x >= Game.WIDTH - 16) velX *= -1;
handler.addObject(new Trail((int)x, (int)y, ID.Trail, col, 16, 16, 0.015f, handler));
}
public void render(Graphics g)
{
g.setColor(col);
g.fillRect((int)x, (int)y, 16, 16);
}
}