-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsnake.c
More file actions
74 lines (60 loc) · 1.27 KB
/
snake.c
File metadata and controls
74 lines (60 loc) · 1.27 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
void snake(){
this.length = 0;
this.y = 0;
this.x = 0;
this.xspeed = 1;
this.yspeed = 0;
this.direction = "right";
}
void update(){
this.x = this.x + this.xspeed;
this.y = this.y + this.yspeed;
if(getbtns == 0xf0f0 | 0xf00f | 0x0ff0 | 0x0f0f){
keyPress(getbtns());
}
delay(1000);
}
void getbtns(void){
int btn = (PORTD >> 5) & 0x0007;
return btn;
}
void keyPress(int buttons){
// 0 0 0 0 = UP DOWN LEFT RIGHT
//Svänga upp
if(buttons & 0xf000){
if(this.direction == "down")
break;
this.xspeed = 0;
this.yspeed = 1;
this.direction = "up";
}
//Svänga ner
if(buttons & 0x0f00){
if(this.direction == "up")
break;
this.xspeed = 0;
this.yspeed = -1;
this.direction = "down";
}
//Svänga vänster
if(buttons & 0x00f0){
if(this.direction == "right")
break;
this.xpseed = -1;
this.yspeed = 0;
this.direction = "left";
}
//Svänga höger
if(buttons & 0x000f){
if(this.direction == "left")
break;
this.xpseed = 1;
this.yspeed = 0;
this.direction = "right";
}
}
void draw(){
Snake.update();
}
*/