-
Notifications
You must be signed in to change notification settings - Fork 0
/
MovingMan.jack
93 lines (86 loc) · 2 KB
/
MovingMan.jack
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
class MovingMan{
/**
This class is in charge of moving the man on screen
according to the input received fron the keyboard.
*/
field Man man;
field int width,up,key,speed;
/**
Initiates the place of the man on the bottom of the screen.
*/
constructor MovingMan new(){
let width = 15;
let up =((255*32)-960);
let man = Man.new();
let key = Keyboard.keyPressed();
let speed = 100;
return this;
}
/**
dispose
*/
method void dispose(){
do Memory.deAlloc(this);
return;
}
/**
Redraws the man on the screen.
*/
method void drawMan(){
do man.draw(width,up);
return;
}
/**
draws/erases the man on the screen,
according to the key pressed on the keyboard.
*/
method void run(int key){
if(key = 132){
if(width < 31 ){
do man.erase(width,up);
let width = width + 1 ;
}
}
if(key = 130){
if(width >0 ){
do man.erase(width,up);
let width = width - 1 ;
}
}
if(key = 131){
if(up - 480 > -1){
do man.erase(width,up);
let up = up - 480 ;
}
}
if(key = 133){
if(up + 960 < (255 * 32)){
do man.erase(width,up);
let up = up + 480 ;
}
}
do man.draw(width,up);
return;
}
/**
Increases the current speed of the game.
*/
method void higherSpeed(){
if(speed - 10 > 0){
let speed = speed - 10;
}
return;
}
/**
Returns the horizontal position of the man on the screen.
*/
method int getWidth(){
return width*16;
}
/**
Returns the vertical position of the man on the screen.
*/
method int getHeight(){
return up/32;
}
}