Omnimaga: The Coders Of Tomorrow
Welcome, Guest. Please login or register.
 
Omnimaga: The Coders Of Tomorrow
19 May, 2013, 23:14:16 *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   home   news downloads projects tutorials misc forums rules new posts irc about Login Register  
+-OmnomIRC

You must Register, be logged in and have at least 40 posts to use this shout-box! If it still doesn't show up afterward, it might be that OmnomIRC is disabled for your group or under maintenance.

Note: You can also use an IRC client like mIRC, X-Chat or Mibbit to connect to an EFnet server and #omnimaga.

Pages: [1]   Go Down
  Print  
Author Topic: Simon: The first pSDL game -  (Read 428 times) Bookmark and Share
0 Members and 1 Guest are viewing this topic.
ruler501
Crazy Freshman
LV11 Super Veteran (Next: 3000)
***********
Online Online

Gender: Male
Last Login: Today at 23:05:14
Date Registered: 08 November, 2010, 02:32:33
Location: In a cave with two spots of light and lots of meat
Posts: 2381


Topic starter
Total Post Ratings: +49

View Profile
« on: 30 June, 2012, 18:03:16 »
0

I created Simon the memory game for prizm using pSDL to show the basics of what it can currently do(I'm working on image loading and I may be able to finish before I leave tomorrow).
At the first menu heres what you can do
Press 1 to start it with text at the bottom for which arrow it maps to
press AC/ON to start without the help
press esc to exit

while it is running it will who each color/help if you enabled it for 3/4 of a second and then once all are shown it will go to black and you can start inputing arrows and the screen will change to the appropriate color
if you manage to get to 25 correct you win(the game)

My code is not exactly the best example of SDL code but here it is...
Spoiler for code:

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
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
#include <SDL.h>
#include <fxcg_syscalls.h>
#include <fxcg/display.h>
#include <stdlib.h>
#include <string.h>

static unsigned long next = 1;
/* RAND_MAX assumed to be 32767 */
int sys_rand(void) {
    next = next * 1103515245 + 12345;
    return((unsigned)(next/65536) % 32768);
}

void sys_srand(unsigned seed) {
    next = seed;
}


int main()
{
SDL_Surface *screen;
int i, j, k, width, height, bpp, done=0, printCase=0, win=1;
SDL_Event event;
SDL_Init(SDL_INIT_VIDEO|SDL_INIT_TIMER);
width = 384;
height = 216;
bpp = 8;
SDL_Color palette[5];
palette[0].r=255; palette[1].g=0; palette[1].r=0;
palette[1].r=0; palette[2].g=255; palette[2].b=0;
palette[2].r=0; palette[3].g=0; palette[3].b=255;
palette[3].r=255; palette[0].g=255; palette[0].b=255;
palette[4].r=0; palette[4].g=0; palette[4].b=0;
screen = SDL_SetVideoMode(width, height, bpp, SDL_SWSURFACE);
SDL_SetColors(screen, palette, 0, 4);
if (screen == NULL) return -1;
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
SDL_UpdateRect(screen, 0, 0, 0, 0);
PrintXY(1, 1, "XXPress AC/ON to start", 0x20, TEXT_COLOR_WHITE);
PrintXY(1, 2, "XXPress Esc to Exit", 0x20, TEXT_COLOR_WHITE);
PrintXY(1, 3, "XXPress 1 for help", 0x20, TEXT_COLOR_WHITE);
Bdisp_PutDisp_DD();
while (!done)
{
while(SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN)
{
switch (event.key.keysym.sym)
{
case SDLK_ESCAPE:
return 0;

case SDLK_POWER:
done = 1;
break;

case SDLK_1:
printCase = 1;
done = 1;
break;

default:
break;
}
}
}
if (SDL_GetTicks() > 10000) return 0;
    }
    SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 255, 255, 255));
    SDL_UpdateRect(screen, 0, 0, 0, 0);
    unsigned char set[25];
    unsigned char choice[25];
    sys_srand(SDL_GetTicks());
    for ( i=0; i<25; i++)
    {
set[i] = sys_rand() % 4;
}
for (i=0; i<25; i++)
{
for (j=0; j<i; j++)
{
memset(screen->pixels, set[j], width*height);
SDL_UpdateRect(screen, 0, 0, 0, 0);
if (set[j] > 3)
return -1;
if (printCase)
{
switch (set[j])
{
case 0:
PrintXY(18, 7, "XXUP", 0, TEXT_COLOR_BLACK);
break;

case 1:
PrintXY(16, 7, "XXRIGHT", 0, TEXT_COLOR_BLACK);
break;

case 2:
PrintXY(16, 7, "XXDOWN", 0, TEXT_COLOR_BLACK);
break;

case 3:
PrintXY(16, 7, "XXLEFT", 0, TEXT_COLOR_BLACK);
break;
}
Bdisp_PutDisp_DD();
}
SDL_Delay(750);
}
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0,0,0));
SDL_UpdateRect(screen, 0,0,0,0);
k=0;
while (k<i)
{
while(SDL_PollEvent(&event)) {
if (event.type == SDL_KEYDOWN)
{
switch (event.key.keysym.sym)
{
case SDLK_UP:
choice[k]=0;
memset(screen->pixels, 0, width*height);
SDL_UpdateRect(screen, 0, 0, 0, 0);

k+=1;
break;

case SDLK_RIGHT:
choice[k]=1;
memset(screen->pixels, 1, width*height);
SDL_UpdateRect(screen, 0, 0, 0, 0);
k+=1;
break;

case SDLK_DOWN:
choice[k]=2;
memset(screen->pixels, 2, width*height);
SDL_UpdateRect(screen, 0, 0, 0, 0);
k+=1;
break;

case SDLK_LEFT:
choice[k]=3;
memset(screen->pixels, 3, width*height);
SDL_UpdateRect(screen, 0, 0, 0, 0);
k+=1;
break;

case SDLK_ESCAPE:
win=0;
i=100;
k=105;
break;


default:
break;
}
}
}
}
for (j=0; j<i; j++)
{
if (set[j] != choice[j])
{
win=0;
i=100;
}
}
}
SDL_FillRect(screen, NULL, SDL_MapRGB(screen->format, 0, 0, 0));
SDL_UpdateRect(screen, 0, 0, 0, 0);
if (win == 0) PrintXY(1, 1, "XXSorry You have lost", 0x20, TEXT_COLOR_WHITE);
else PrintXY(1, 1, "XXYou have won the game!", 0x20, TEXT_COLOR_WHITE);
Bdisp_PutDisp_DD();
SDL_Delay(2000);
return 0;
}

EDIT: fixed error where esc could lock up calc



* Simon.g3a (156.68 KB - downloaded 26 times.)
« Last Edit: 30 June, 2012, 19:20:51 by ruler501 » Logged


Spoiler for "Projects":
My current games I am working on our:
  I might have an improved C version of this somewhere...
pSDL too lazy too make a userbar so I'll just link to the topic i update routinely http://www.omnimaga.org/index.php?board=146.0
Spoiler for "Misc images of test things":
NerdTests.com says I'm a Dorky Nerd God.  Click here to take the Nerd Test, get geeky images and jokes, and talk to others on the nerd forum!My computer geek score is greater than 100% of all people in the world! How do you compare? Click here to find out!"<br />[url=http://www.nerdtests.com/ft_personality.php?ref=42769
[/url]
-----BEGIN GEEK CODE BLOCK-----
Version: 3.1
GCM/CS/M/S d- s++: a---- C++ UL++ P+ L++ E---- W++ N o? K- w-- o? !M V?
PS+ PE+ Y+ PGP++ t 5? X R tv-- b+++ DI+ D+ G++ e- h! !r y

------END GEEK CODE BLOCK------
"KnifeOn!  Apply directly to the forehead!  KnifeOn is available without a prescription at retailers nationwide."
DJ Omnimaga
Retired Omnimaga founder (Site issues must be PM'ed to Netham45, Eeems, Shmibs, Deep Thought and AngelFish, not me.)
Editor
LV15 Omnimagician (Next: --)
*
Offline Offline

Gender: Male
Last Login: Today at 19:36:19
Date Registered: 25 August, 2008, 07:00:21
Location: Québec (Canada)
Posts: 50202


Total Post Ratings: +2611

View Profile WWW
« Reply #1 on: 01 July, 2012, 07:30:44 »
0

Oh Nice, I need to try this soon Smiley. Glad to see Omnimaga members venture into PRIZM game programming. I was surprised practically no one here even bothered in the first 1.5 years the calc got released shocked

If you finish before leaving, do you think you could upload it at http://www.omnimaga.org/index.php?action=downloads;sa=add;cat=70 so it gets more visibility?
« Last Edit: 01 July, 2012, 07:32:29 by DJ_O » Logged

Retired 83+ coder, Omnimaga/TIMGUL founder. Now doing power metal music (formerly did electronica)

Follow me on Bandcamp|Facebook|Reverbnation|Youtube|Twitter|Myspace
Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by EzPortal
Powered by MySQL Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Powered by PHP
Page created in 0.218 seconds with 30 queries.
Skin by DJ Omnimaga edited from SMF default theme with the help of tr1p1ea.
All programs, games and songs avaliable on this website are property of their respective owners.
Best viewed in Opera, Firefox, Chrome and Safari with a resolution of 1024x768 or above.