author | Markus Bröker <mbroeker@largo.dyndns.tv> |
Thu, 16 Apr 2009 12:49:12 +0200 | |
changeset 43 | cf8c1b5127b2 |
parent 42 | 83b8151b966d |
child 45 | 7197576fedcf |
permissions | -rw-r--r-- |
9
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
4
diff
changeset
|
1 |
/** |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
4
diff
changeset
|
2 |
* test/demos/pmc/main.cc |
c3fecc82ade6
standard tags for git projects
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
4
diff
changeset
|
3 |
* Copyright (C) 2008 Markus Broeker |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
4 |
*/ |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
5 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
6 |
#include <surface.h> |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
7 |
#include <rectangle.h> |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
8 |
#include <cube.h> |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
9 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
10 |
#include <cstdio> |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
11 |
#include <cstdlib> |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
12 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
13 |
#ifndef STEP |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
14 |
#define STEP 1 |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
15 |
#endif |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
16 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
17 |
#define MAX 3 |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
18 |
|
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
19 |
int main (int argc, char **argv) |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
20 |
{ |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
21 |
Surface *surface; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
22 |
SDL_Event event; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
23 |
Drawable *d[MAX]; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
24 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
25 |
int height; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
26 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
27 |
if (argc != 2) { |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
28 |
fprintf (stderr, "Usage: %s <HEIGHT>\n", argv[0]); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
29 |
height = 250; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
30 |
} else |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
31 |
height = atoi (argv[1]); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
32 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
33 |
if ((height < 10) || (height >= 360)) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
34 |
height = 200; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
35 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
36 |
Vector p1 (0, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
37 |
Vector p2 (height, 0); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
38 |
Vector p3 (height, height); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
39 |
Vector p4 (0, height); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
40 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
41 |
surface = new Surface (1024, 768, 16); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
42 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
43 |
d[0] = new Rectangle (surface, p1, p2, p3, p4); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
44 |
d[1] = new Cube (surface); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
45 |
d[2] = new Cube (surface, p1, p2, p3, p4, height); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
46 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
47 |
bool running = true; |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
48 |
int x, y; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
49 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
50 |
x = y = 0; |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
51 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
52 |
d[1]->move (Vector (25, 25)); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
53 |
d[2]->move (Vector (290, 0)); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
54 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
55 |
while (running) { |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
56 |
SDL_PollEvent (&event); |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
57 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
58 |
if (event.type == SDL_QUIT) |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
59 |
running = false; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
60 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
61 |
if (event.type == SDL_KEYDOWN) { |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
62 |
surface->setColor (Surface::BLACK); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
63 |
for (int i = 0; i < MAX; i++) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
64 |
d[i]->show (); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
65 |
surface->setColor (Surface::RED); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
66 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
67 |
switch (event.key.keysym.sym) { |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
68 |
case SDLK_ESCAPE: |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
69 |
running = false; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
70 |
break; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
71 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
72 |
case SDLK_UP: |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
73 |
for (int i = 0; i < MAX; i++) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
74 |
d[i]->move ((Vector (x, y - STEP))); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
75 |
break; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
76 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
77 |
case SDLK_DOWN: |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
78 |
for (int i = 0; i < MAX; i++) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
79 |
d[i]->move ((Vector (x, y + STEP))); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
80 |
break; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
81 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
82 |
case SDLK_LEFT: |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
83 |
for (int i = 0; i < MAX; i++) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
84 |
d[i]->move ((Vector (x - STEP, y))); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
85 |
break; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
86 |
|
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
87 |
case SDLK_RIGHT: |
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
88 |
for (int i = 0; i < MAX; i++) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
89 |
d[i]->move ((Vector (x + STEP, y))); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
90 |
break; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
91 |
default: |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
92 |
break; |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
93 |
} |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
94 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
95 |
for (int i = 0; i < MAX; i++) { |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
96 |
d[i]->show (); |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
97 |
} |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
98 |
|
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
99 |
surface->flip (); |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
100 |
} |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
101 |
} |
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
102 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
103 |
for (int i = 0; i < MAX; i++) |
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
104 |
delete d[i]; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
105 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
106 |
delete surface; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
107 |
|
42
83b8151b966d
Klassenhierarchie erneuert, Codebase erneuert
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
9
diff
changeset
|
108 |
return EXIT_SUCCESS; |
4
236f8f747073
pimp my code, a small xdemo
Markus Bröker <mbroeker@largo.dyndns.tv>
parents:
diff
changeset
|
109 |
} |