9
9
#include "buttons.h"
10
10
#include "display.h"
11
11
12
+ #define LEVEL_WIDTH 320 // 2*DISPLAY_WIDTH
13
+
12
14
#define ON_THE_GROUND 0
13
15
#define FALLING_DOWN 7
14
16
15
17
void init ();
16
18
17
19
void drawmonster (int x , int y )
20
+ {
21
+ page (x , y , 0b11010000 );
22
+ page (x + 1 , y , 0b11110000 );
23
+ page (x + 2 , y , 0b11111100 );
24
+ page (x + 3 , y , 0b11110111 );
25
+ page (x + 4 , y , 0b11110111 );
26
+ page (x + 5 , y , 0b00110111 );
27
+ page (x + 6 , y , 0b00000011 );
28
+ page (x , y + 1 , 0b00000111 );
29
+ page (x + 1 , y + 1 , 0xFF );
30
+ page (x + 2 , y + 1 , 0xFF );
31
+ page (x + 3 , y + 1 , 0xFF );
32
+ page (x + 4 , y + 1 , 0xFF );
33
+ page (x + 5 , y + 1 , 0b00001111 );
34
+ page (x + 6 , y + 1 , 0b00000101 );
35
+ page (x , y + 2 , 0b11010000 );
36
+ page (x + 1 , y + 2 , 0b11111101 );
37
+ page (x + 2 , y + 2 , 0b11001111 );
38
+ page (x + 3 , y + 2 , 0b00000011 );
39
+ page (x + 4 , y + 2 , 0b11010011 );
40
+ page (x + 5 , y + 2 , 0xFF );
41
+ page (x + 6 , y + 2 , 0b11001100 );
42
+ }
43
+
44
+
45
+ void drawdoor ()
46
+ {
47
+ page (0 ,24 , 0xFF );
48
+ page (1 ,24 , 0xFF );
49
+ page (2 ,24 , 0xFF );
50
+ page (0 ,23 , 0xFF );
51
+ page (1 ,23 , 0xFF );
52
+ page (2 ,23 , 0xFF );
53
+ page (0 ,22 , 0xFF );
54
+ page (1 ,22 , 0xFF );
55
+ page (2 ,22 , 0xFF );
56
+ page (0 ,21 , 0xFF );
57
+ page (1 ,21 , 0xFF );
58
+ page (2 ,21 , 0xFF );
59
+ page (0 ,20 , 0xFF );
60
+ page (1 ,20 , 0xFF );
61
+ page (2 ,20 , 0xFF );
62
+
63
+ }
64
+
65
+ void drawcharacter (int x , int y )
18
66
{
19
67
page (x , y , 0xFF );
20
68
page (x + 1 , y , 0b11010011 );
@@ -54,9 +102,12 @@ void drawfloor()
54
102
}
55
103
}
56
104
105
+ long level_seed ;
106
+ long level_pos = 0 ;
57
107
long platforms ;
58
108
void drawplatform ()
59
109
{
110
+ srandom (level_seed + level_pos );
60
111
platforms = random ();
61
112
for (uint8_t pos = 0 ; pos < DISPLAY_WIDTH /8 ; ++ pos ) // draw random platforms at 20 possible positions
62
113
{
@@ -77,15 +128,24 @@ long platform(int x, int y)
77
128
else
78
129
return 0 ;
79
130
}
131
+
132
+ void redraw ()
133
+ {
134
+ clear ();
135
+ drawfloor ();
136
+ drawplatform ();
137
+ }
80
138
81
139
int main (void )
82
140
{
83
141
init ();
84
- drawfloor ();
85
- drawplatform ();
142
+ level_seed = random ();
143
+ redraw ();
144
+ drawdoor ();
145
+ drawmonster (140 , 22 );
86
146
int x = 10 ;
87
147
int y = 22 ;
88
- drawmonster (x ,y );
148
+ drawcharacter (x ,y );
89
149
int jumpcounter = ON_THE_GROUND ;
90
150
uint32_t nextmoveevent = 0 ;
91
151
uint32_t nextjumpevent = 0 ;
@@ -98,12 +158,11 @@ int main(void)
98
158
{
99
159
if (x + 7 == DISPLAY_WIDTH )
100
160
{
101
- clear ();
102
- drawfloor ();
103
- drawplatform ();
161
+ ++ level_pos ;
162
+ redraw ();
104
163
x = 0 ;
105
164
//y = 22;
106
- drawmonster (x ,y );
165
+ drawcharacter (x ,y );
107
166
}
108
167
else if (!platform (x + 7 ,y ) && !platform (x + 7 , y + 1 )&& !platform (x + 7 , y + 2 ))
109
168
{
@@ -115,20 +174,28 @@ int main(void)
115
174
page (x , y , 0x00 );
116
175
page (x , y + 1 , 0x00 );
117
176
page (x , y + 2 , 0x00 );
118
- drawmonster (++ x , y );
177
+ drawcharacter (++ x , y );
119
178
nextmoveevent = getMsTimer () + 50 ;
120
179
}
121
180
}
122
181
if (B_LEFT && !platform (x - 1 ,y ) && !platform (x - 1 , y + 1 )&& !platform (x - 1 , y + 2 ))
123
182
{
183
+ if (x == 0 )
184
+ {
185
+ -- level_pos ;
186
+ redraw ();
187
+ x = 153 ;
188
+ //y = 22;
189
+ drawcharacter (x ,y );
190
+ }
124
191
if (platform (x + 6 ,y + 3 ) && !platform (x + 5 ,y + 3 ))
125
192
{
126
193
jumpcounter = FALLING_DOWN ;
127
194
}
128
195
page (x + 6 , y , 0x00 );
129
196
page (x + 6 , y + 1 , 0x00 );
130
197
page (x + 6 , y + 2 , 0x00 );
131
- drawmonster (-- x , y );
198
+ drawcharacter (-- x , y );
132
199
nextmoveevent = getMsTimer () + 50 ;
133
200
}
134
201
}
@@ -151,7 +218,7 @@ int main(void)
151
218
page (x + 5 , y + 2 , 0x00 );
152
219
page (x + 6 , y + 2 , 0x00 );
153
220
y = y - 1 ;
154
- drawmonster (x , y );
221
+ drawcharacter (x , y );
155
222
++ jumpcounter ;
156
223
}
157
224
else //fallen
@@ -167,7 +234,7 @@ int main(void)
167
234
page (x + 5 , y , 0x00 );
168
235
page (x + 6 , y , 0x00 );
169
236
++ y ;
170
- drawmonster (x , y );
237
+ drawcharacter (x , y );
171
238
}
172
239
else //boden oder Plattform erreicht
173
240
{
0 commit comments