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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#include <stdlib.h>
#include <assert.h>
#include <string.h>
#include "main.h"
#include "arena.h"
#include "list.h"
#include "tux.h"
#include "shot.h"
#include "wall.h"
#include "item.h"
#include "teleport.h"
#include "pipe.h"
#ifndef PUBLIC_SERVER
#include "layer.h"
#endif
static arena_t *currentArena;
void setCurrentArena(arena_t *p)
{
currentArena = p;
}
arena_t* getCurrentArena()
{
return currentArena;
}
arena_t* newArena()
{
arena_t *new;
new = malloc( sizeof(arena_t) );
#ifndef PUBLIC_SERVER
new->background = NULL;
strcpy(new->music, "");
#endif
new->listTux = newList();
new->listShot = newList();
new->listWall = newList();
new->listItem = newList();
new->listTeleport = newList();
new->listPipe = newList();
return new;
}
int conflictSpace(int x1,int y1,int w1,int h1,int x2,int y2,int w2,int h2)
{
return (x1<x2+w2 && x2<x1+w1 && y1<y2+h2 && y2<y1+h1);
}
int isFreeSpace(arena_t *arena, int x, int y, int w, int h)
{
if ( isConflictWithListTux(arena->listTux, x, y, w, h) )return 0;
if ( isConflictWithListWall(arena->listWall, x, y, w, h) )return 0;
if ( isConflictWithListShot(arena->listShot, x, y, w, h) )return 0;
if ( isConflictWithListItem(arena->listItem, x, y, w, h) )return 0;
if ( isConflictWithListTeleport(arena->listTeleport, x, y, w, h) )return 0;
if ( isConflictWithListPipe(arena->listPipe, x, y, w, h) )return 0;
return 1;
}
void findFreeSpace(arena_t *arena, int *x, int *y, int w, int h)
{
int z_x;
int z_y;
assert( x != NULL );
assert( y != NULL );
do{
z_x = random() % WINDOW_SIZE_X;
z_y = random() % (WINDOW_SIZE_Y-200);
}while( isFreeSpace(arena, z_x, z_y ,w ,h) == 0 );
*x = z_x;
*y = z_y;
}
#ifndef PUBLIC_SERVER
void drawArena(arena_t *arena)
{
tux_t *tux = NULL;
addLayer(arena->background, 0, 0, 0, 0, WINDOW_SIZE_X, WINDOW_SIZE_Y, -100);
drawListTux(arena->listTux);
drawListWall(arena->listWall);
drawListTeleport(arena->listTeleport);
drawListPipe(arena->listPipe);
drawListShot(arena->listShot);
drawListItem(arena->listItem);
/*
tux = getControlTux( TUX_CONTROL_KEYBOARD_RIGHT );
*/
if( tux == NULL )
{
drawLayerCenter(WINDOW_SIZE_X/2, WINDOW_SIZE_Y/2);
}
else
{
drawLayerCenter(tux->x, tux->y);
}
}
#endif
void eventArena(arena_t *arena)
{
int i;
eventConflictTuxWithTeleport(arena->listTux, arena->listTeleport);
eventConflictTuxWithShot(arena->listTux, arena->listShot);
for( i = 0 ; i < 4 ; i++)
{
eventMoveListShot(arena->listShot);
eventConflictShotWithWall(arena->listWall, arena->listShot);
eventConflictShotWithTeleport(arena->listTeleport, arena->listShot);
eventConflictShotWithPipe(arena->listPipe, arena->listShot);
eventConflictShotWithItem(arena->listItem, arena->listShot);
}
eventListItem(arena->listItem);
eventListTux(arena->listTux);
}
void destroyArena(arena_t *p)
{
destroyListItem(p->listTux, destroyTux);
destroyListItem(p->listShot, destroyShot);
destroyListItem(p->listWall, destroyWall);
destroyListItem(p->listItem, destroyItem);
destroyListItem(p->listTeleport, destroyItem);
destroyListItem(p->listPipe, destroyItem);
free(p);
}
|