-
Notifications
You must be signed in to change notification settings - Fork 0
/
snake_game.pde
100 lines (99 loc) · 1.67 KB
/
snake_game.pde
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
import processing.sound.*;
snake s;
food f;
begin st;
over o;
float hscore;
int play =0 ;
SoundFile eat;
void setup()
{
fullScreen();
f = new food();
s = new snake();
st = new begin();
o = new over();
String s[] = loadStrings("scorefile.txt");
hscore = Float.parseFloat(s[0]);
eat = new SoundFile(this,"eat.wav");
}
void draw()
{
if (play==0)
{
background(0, 255, 155);
st.display();
st.update();
textSize(20);
text("HighScore :", 10, 20);
text((int)hscore, 120, 20);
//if (dist(mouseX, mouseY, width/2, height/2)<100)
//{
// cursor(HAND);
//} else
//{
// cursor(ARROW);
//}
}
if (play==1)
{
background(0, 255, 155);
f.display();
s.display();
s.update();
s.checkEdges();
if (s.eat(f.x, f.y))
{
f.foodlocation();
eat.play();
}
s.dead();
//if(s.total+1>10)
// frameRate(15);
//else
// frameRate(10);
}
if (play== 2)
{
background(0, 255, 155);
o.display();
o.update();
//if (dist(mouseX, mouseY, width/2, height/2)<200)
//{
// cursor(HAND);
//} else
//{
// cursor(ARROW);
//}
}
}
void keyPressed()
{
if (key == CODED)
{
if (keyCode == UP)
{
s.direction(0, -20);
}
else if (keyCode == DOWN)
{
s.direction(0, 20);
}
else if (keyCode == RIGHT)
{
s.direction(20, 0);
}
else if (keyCode == LEFT)
{
s.direction(-20, 0);
}
}
}
void mouseClicked()
{
if (dist(mouseX, mouseY, width/2, height/2)<100)
{
play = 1;
frameRate(10);
}
}