forked from pratyushmp/code_opensource_2020
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathPlayState.java
More file actions
52 lines (41 loc) · 1.33 KB
/
PlayState.java
File metadata and controls
52 lines (41 loc) · 1.33 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
import java.awt.*;
import javax.swing.*;
public class PlayState extends AbstractGameState
{
private Sprite player;
private Sprite baddie;
public PlayState(GameView view)
{
super(view);
Image image;
image = new ImageIcon("/images/player.png").getImage();
this.player = new Sprite();
this.player.setImage(image);
this.player.setPosition(400, 200);
image = new ImageIcon("/images/baddie.png").getImage();
this.baddie = new BouncingSprite();
this.baddie.setImage(image);
this.baddie.setPosition(200, 300);
this.baddie.setMotion(0, 10);
this.getView().startClock(50);
}
public void drawOn(Graphics g)
{
Rectangle bounds = this.getView().getBounds();
g.setColor(Color.ORANGE);
g.fillRect(0, 0, bounds.width, bounds.height);
this.player.drawOn(g);
this.baddie.drawOn(g);
}
public void clocktick()
{
this.baddie.clocktick();
if (this.baddie.getRect().intersects(this.player.getRect()))
{
this.getView().setState(new GameOverState(this.getView()));
}
}
public void handleMouseMoved(int mouseX, int mouseY)
{
this.player.setPosition(mouseX, this.player.getY());
}