Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Latest commit

 

History

History
executable file
·
89 lines (80 loc) · 2.33 KB

File metadata and controls

executable file
·
89 lines (80 loc) · 2.33 KB
 
Feb 13, 2012
Feb 13, 2012
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/*
* Really basic sample for the NDS.
*
* Fills a rectangle increasingly smaller of random color every time a
* button (a, b, x, y) is pressed.
*
* The behaviour whether SDL is compiled with HW support or not (see
* USE_HW_RENDERER in Makefile.ds).
*
* In framebuffer mode, the old rectangles stay because the screen has
* not been cleared.
*
* In accelerated mode, old the last rectangle is visible.
*
* No text is displayed.
*/
Jun 22, 2011
Jun 22, 2011
18
19
20
21
22
23
24
25
26
27
#include <SDL/SDL.h>
#if defined(NDS) || defined(__NDS__) || defined (__NDS)
#include <nds.h>
#include <fat.h>
#else
#define consoleDemoInit()
#define fatInitDefault()
#define RGB15(r,g,b) SDL_MapRGB(screen->format,((r)<<3),((g)<<3),((b)<<3))
#endif
Feb 13, 2012
Feb 13, 2012
28
int main(void)
Jun 22, 2011
Jun 22, 2011
29
{
Feb 13, 2012
Feb 13, 2012
30
31
SDL_Window *window;
SDL_Renderer *renderer;
Jun 22, 2011
Jun 22, 2011
32
33
34
35
36
37
38
SDL_Joystick *stick;
SDL_Event event;
SDL_Rect rect = { 0, 0, 256, 192 };
int i;
consoleDemoInit();
puts("Hello world! Initializing FAT...");
Feb 13, 2012
Feb 13, 2012
39
40
if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_JOYSTICK) < 0) {
Jun 22, 2011
Jun 22, 2011
41
42
43
44
45
puts("# error initializing SDL");
puts(SDL_GetError());
return 1;
}
puts("* initialized SDL");
Feb 13, 2012
Feb 13, 2012
46
47
48
49
if (SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_ACCELERATED, &window, &renderer) < 0 &&
SDL_CreateWindowAndRenderer(256, 192, SDL_RENDERER_SOFTWARE, &window, &renderer) < 0) {
exit(1);
Jun 22, 2011
Jun 22, 2011
50
}
Feb 13, 2012
Feb 13, 2012
51
Jun 22, 2011
Jun 22, 2011
52
53
54
55
56
57
58
stick = SDL_JoystickOpen(0);
if (stick == NULL) {
puts("# error opening joystick");
puts(SDL_GetError());
}
puts("* opened joystick");
Feb 13, 2012
Feb 13, 2012
59
60
61
SDL_SetRenderDrawColor(renderer, 0, 0, 0, SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer);
Jun 22, 2011
Jun 22, 2011
62
63
64
65
66
while (1)
while (SDL_PollEvent(&event))
switch (event.type) {
case SDL_JOYBUTTONDOWN:
Feb 13, 2012
Feb 13, 2012
67
68
69
70
SDL_SetRenderDrawColor(renderer, rand(), rand(), rand(), SDL_ALPHA_OPAQUE);
SDL_RenderFillRect(renderer, &rect);
SDL_RenderPresent(renderer);
Jun 22, 2011
Jun 22, 2011
71
72
73
74
75
76
if (rect.w > 8) {
rect.x += 4;
rect.y += 3;
rect.w -= 8;
rect.h -= 6;
}
Feb 13, 2012
Feb 13, 2012
77
78
79
80
/*
printf("button %d pressed at %d ticks\n",
event.jbutton.button, SDL_GetTicks());
*/
Jun 22, 2011
Jun 22, 2011
81
82
83
84
85
86
87
break;
case SDL_QUIT:
SDL_Quit();
return 0;
default:
break;
}
Feb 13, 2012
Feb 13, 2012
88
89
return 0;
}