Back from North Carolina…with much more knowledge of Perl

So…I did very little over the past 5 days. Ate, slept, played Warcraft III, and Perled. Lots of Perling. I can now write a semi-competent script to do something other that format the printing of “Hello, World!”. When I got back tonight, I went straight to my computer and threw together another monosynthic song, which isn’t up on reverb yet. About the end of this month I’ll albumize it and put it up on jamendo. I can’t find it now but the thing that brought the music to mind was someone who recorded the sound of his perl script collection and put it up on jamendo. Some of them (which he claims were the better-written ones with strict pragma) were actually very good. Anyway, I start work tomorrow writing the backend of my new employer’s commerce site. I anticipate more than one stress-wracked night of tossing and turning wondering if my security is up to par…

Got a job, going on vacation, and uploaded some new music

Alright, today I interviewed (and got) a job working for a small company here in town. I will be working on the backend of their website and will be getting 8$/hour and working ~40hours a week. That’s quite a bit of money for someone still in high school (~320$). Also, I realize now how stupid it was to start the 14DRL when I am going on vacation tomorrow xD. So I will continue that after I get back next monday. I start work next Tuesday, so it may be put off a bit longer.

One last thing, even though my reverbnation profile hasn’t been updated in almost a month, I have been making music. I put up three new ones just now. Marvel, Stop the FUD, and Timarus. Have at ‘em at http://reverbnation.com/segfult. (WARNING: minimalist techno/trance. No flames if you don’t like that genre)

P.S. for Crouse: I reeeeaaally like the blog theme. Please don’t change it.

14 Day Roguelike – Day III

Today I finally overcame my collision detection troubles. I also added mobs that randomly move around. They have a Damage Point (dp) and Armor Point (ap) rating, as well as a Health Point (hp) rating. My attack_mob(int y, int x) function works perfectly except that it apparently doesn’t store the new HP value in mobs[i].hp. Eventually I’ll figure out how to make that work…eventually.

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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
#include "curses.h"
#include "signal.h"
#include "stdlib.h"
#include "time.h"
 
//Define the map height and width
#define MAP_HEIGHT 40
#define MAP_WIDTH 30
 
//Create the 2D arrays for the floor and walls
bool floor[MAP_HEIGHT][MAP_WIDTH];
bool walls[MAP_HEIGHT][MAP_WIDTH];
 
//NCurses player yx
int player_y = 0;
int player_x = 0;
//Map player yx
int player_map_y = MAP_HEIGHT / 2;
int player_map_x = MAP_WIDTH / 2;
 
//Function prototypes
static void finish(int sig);
static bool proc_in(int c);
static void draw_map();
static void draw_player();
static void init_player();
static void init_mobs();
static void draw_mobs();
static void proc_mobs();
static bool check_collision(int y, int x);
static void attack_mob(int y, int x);
 
typedef struct mob_
{
        //NCurses Coordinates
        int nc_y;
        int nc_x;
        //Map Coordinates
        int mp_y;
        int mp_x;
        //Combat stuff
        int hp;
        int dp;
        int ap;
} mob;
 
 
typedef struct player_
{
        int nc_y;
        int nc_x;
        int mp_y;
        int mp_x;
        int hp;
        int dp;
        int ap;
} player;
 
int test = MAP_HEIGHT / 10;
 
mob mobs[MAP_HEIGHT / 10];
 
player p;
 
//MAIN
int main(int argc, char * argv[])
{
        //endwin() on SIGINT
        (void)signal(SIGINT, finish);
        //NCurses init stuff
        (void)initscr();
        (void)keypad(stdscr, TRUE);
        (void)cbreak();
        (void)noecho();
        (void)nonl();
 
        //Seed rand using time
        srand(time(NULL));
        //Generate a basic map
        int y = 0;
        int x = 0;
        for(y = 0; y < MAP_HEIGHT; y++)
        {
                for(x = 0; x < MAP_WIDTH; x++)
                {
                        floor[y][x] = TRUE;
                }
        }
        for(y = 0; y < MAP_HEIGHT; y++)
        {
                        walls[y][0] = TRUE;
                        walls[y][MAP_WIDTH - 1] = TRUE;
        }
        for(x = 0; x < MAP_WIDTH; x++)
        {
                walls[0][x] = TRUE;
                walls[MAP_HEIGHT - 1][x] = TRUE;
        }
        //Init the player
        init_player();
        //Init the mobs
        init_mobs();
        //Draw the map
        draw_map();
        //Draw the mobs
        draw_mobs();
        //Draw the player
        draw_player();
        //Refresh the screen
        refresh();
 
        //Loop forever
        while(TRUE)
        {
                //Only refresh the screen if something happens
                if(proc_in(getch()) == TRUE)
                {
                        //Process the mobs
                        proc_mobs();
                        //Draw the map;
                        draw_map();
                        //Draw the mobs
                        draw_mobs();
                        //Draw the player
                        draw_player();
                        //Refresh the screen
                        refresh();
                }
        }
        return 0;
}
 
static bool proc_in(int c)
{
        //Process the key that was pressed
        switch(c)
        {
                case '4': //If 4 then move left
                        if(check_collision(p.mp_y, p.mp_x - 1))
                        {
                                p.nc_x--;
                                p.mp_x--;
                        }
                        return TRUE;
                        break;
                case '6': //If 6 then move right
                        if(check_collision(p.mp_y, p.mp_x + 1))//But only if there is no wall
                        {
                                p.nc_x++;
                                p.mp_x++;
                        }
                        return TRUE;
                        break;
                case '8': //If 8 then move up
                        if(check_collision(p.mp_y - 1, p.mp_x))//But only if there is no wall
                        {
                                p.nc_y--;
                                p.mp_y--;
                        }
                        return TRUE;
                        break;
                case '2': //If 2 then move down
                        if(check_collision(p.mp_y + 1, p.mp_x))//But only if there is no wall
                        {
                                p.nc_y++;
                                p.mp_y++;
                        }
                        return TRUE;
                        break;
                case '1': //If 1 then move down and left
                        if(check_collision(p.mp_y + 1, p.mp_x - 1))//But only if there is no wall
                        {
                                p.nc_y++;
                                p.mp_y++;
                                p.nc_x--;
                                p.mp_x--;
                        }
                        return TRUE;
                        break;
                case '3': //If 3 then move down and right
                        if(check_collision(p.mp_y + 1, p.mp_x + 1))//But only if there is no wall
                        {
                                p.nc_y++;
                                p.mp_y++;
                                p.nc_x++;
                                p.mp_x++;
                        }
                        return TRUE;
                        break;
                case '7': //If 7 then move up and left
                        if(check_collision(p.mp_y - 1, p.mp_x - 1)) //But only if there is no wall
                        {
                                p.nc_y--;
                                p.mp_y--;
                                p.nc_x--;
                                p.mp_x--;
                        }
                        return TRUE;
                        break;
                case '9': //If 8 then move up and right
                        if(check_collision(p.mp_y - 1, p.mp_x + 1)) //But only if there is no wall
                        {
                                p.nc_y--;
                                p.mp_y--;
                                p.nc_x++;
                                p.mp_x++;
                        }
                        return TRUE;
                        break;
                case '.':
                        return TRUE;
                        break;
        }
        return FALSE;
}
 
 
static void draw_map()
{
        //Draw the map
        int y = 0;
        int x = 0;
        for(y = 0; y < MAP_HEIGHT; y++)
        {
                for(x = 0; x < MAP_WIDTH; x++)
                {
                        //If there is a floor on cell yx
                        if(floor[y][x] == TRUE)
                        {
                                //Draw it
                                mvaddch((LINES / 2 - MAP_HEIGHT / 2) + y,(COLS / 2 - MAP_WIDTH / 2) +  x, '.');
                        }
                }
        }
        move(0, 0);
        for(y = 0; y < MAP_HEIGHT; y++)
        {
                for(x = 0; x < MAP_WIDTH; x++)
                {
                        //If there is a wall on cell yx
                        if(walls[y][x] == TRUE)
                        {
                                //Draw it
                                mvaddch((LINES / 2 - MAP_HEIGHT / 2) + y,(COLS / 2 - MAP_WIDTH / 2) +  x, 'W');
                        }
                }
        }
        move(0, 0);
}
 
static void draw_player()
{
        mvaddch(p.nc_y, p.nc_x, '@');
        move(0,0);
}
 
static void finish(int sig)
{
        endwin();
        exit(0);
}
 
static void init_player()
{
        p.mp_y = MAP_HEIGHT / 2;
        p.mp_x = MAP_WIDTH / 2;
        p.nc_y = (LINES / 2 - MAP_HEIGHT / 2) + p.mp_y;
        p.nc_x = (COLS / 2 - MAP_WIDTH / 2) + p.mp_x;
        p.hp = 100;
        p.dp = 10;
        p.ap = 25;
}
 
static void init_mobs()
{
        int i = 0;
        for(i = 0; i < sizeof(mobs) / sizeof(mob); i++)
        {
                mobs[i].mp_y = rand()%(MAP_HEIGHT - 5) + 1;
                mobs[i].mp_x = rand()%(MAP_WIDTH - 5) + 1;
                mobs[i].nc_y = (LINES / 2 - MAP_HEIGHT / 2) + mobs[i].mp_y;
                mobs[i].nc_x = (COLS / 2 - MAP_WIDTH / 2) + mobs[i].mp_x;
                mobs[i].hp = rand()%250 + 1;
                mobs[i].dp = rand()%25 + 1;
                mobs[i].ap = rand()%50 + 1;
        }
}
 
static void draw_mobs()
{
        int i = 0;
        for(i = 0; i  0)
                {
                        mvaddch(mobs[i].nc_y, mobs[i].nc_x, 'm');
                }
                else
                {
                        mvaddch(mobs[i].nc_y, mobs[i].nc_x, 'x');
                }
        }
        move(0, 0);
}
 
static void proc_mobs()
{
        int i = 0;
        for(i = 0; i  0)
                {
                        int a = rand()%4;
                        int y = rand()%2;
                        int x = rand()%2;
                        switch(a){
                                case 0:
                                        if(y == 0 && check_collision(mobs[i].mp_y -1, mobs[i].mp_x))
                                        {
                                                mobs[i].nc_y--;
                                                mobs[i].mp_y--;
                                        }
                                        else if(y == 1 && check_collision(mobs[i].mp_y +1, mobs[i].mp_x))
                                        {
                                                mobs[i].nc_y++;
                                                mobs[i].mp_y++;
                                        }
                                        break;
                                case 1:
                                        if(x == 0 && check_collision(mobs[i].mp_y, mobs[i].mp_x -1))
                                        {
                                                mobs[i].nc_x--;
                                                mobs[i].mp_x--;
                                        }
                                        else if(x == 1 && check_collision(mobs[i].mp_y, mobs[i].mp_x +1))
                                        {
                                                mobs[i].nc_x++;
                                                mobs[i].mp_x++;
                                        }
                                        break;
                                case 2:
                                        if(y == 0 && check_collision(mobs[i].mp_y -1, mobs[i].mp_x))
                                        {
                                                mobs[i].nc_y--;
                                                mobs[i].mp_y--;
                                        }
                                        else if(y == 1 && check_collision(mobs[i].mp_y +1, mobs[i].mp_x))
                                        {
                                                mobs[i].nc_y++;
                                                mobs[i].mp_y++;
                                        }
                                        if(x == 0 && check_collision(mobs[i].mp_y, mobs[i].mp_x -1))
                                        {
                                                mobs[i].nc_x--;
                                                mobs[i].mp_x--;
                                        }
                                        else if(x == 1 && check_collision(mobs[i].mp_y, mobs[i].mp_x +1))
                                        {
                                                mobs[i].nc_x++;
                                                mobs[i].mp_x++;
                                        }
                                        break;
                                case 3:
                                        break;
                        }
                }
        }
}
 
static bool check_collision(int y, int x)
{
        int check = 0;
        if(walls[y][x] == FALSE && floor[y][x] == TRUE)
        {
                if(y != p.mp_y || x != p.mp_x)
                {
                        int i = 0;
                        for(i = 0; i  0)
                                {
                                        if(y != mobs[i].mp_y || x != mobs[i].mp_x)
                                        {
                                                check++;
                                        }
                                        else
                                        {
                                                attack_mob(y, x);
                                        }
                                }
                        }
                }
        }
        if(check == sizeof(mobs) / sizeof(mob))
        {
                return TRUE;
        }
        else
        {
                return FALSE;
        }
}
 
static void attack_mob(int y, int x)
{
        int i = 0;
        for(i = 0; i < sizeof(mobs) / sizeof(mob); i++)
        {
                if(mobs[i].mp_y == y && mobs[i].mp_x == x)
                {
                        int damage = 0;
                        int i = 0;
                        for(i = 0; i <= p.dp; i++)
                        {
                                damage = damage + rand()%6 + 1;
                        }
                        for(i = 0; i <= mobs[i].ap; i++)
                        {
                                damage = damage - rand()%4 + 1;
                        }
 
                        mobs[i].hp -= damage;
                        move(0, 0);
                        if(mobs[i].hp <= 0)
                        {
                                printf("You hit monster for %d damage. You killed monster", damage);
                        }
                        else
                        {
                                printf("You hit monster for %d damage.", damage);
                        }
                        move(0, 0);
                }
        }
}

14 Day Rouge-like – Day II

Today I played around with rewriting everything from scratch in C++. It ended up being object oriented but a pain to use, so I went back to my C implementation. The map system I reimplemented in layers ( a wall layer and a floor layer right now). Trouble is, it still doesn’t detect collisions. I found out that my problem was lack of planning. My player_x and player_y variables use NCurses-relative coordinates, whereas the wall[y][x] is map-relative.  So now I will rewrite that one more time and get it working. If I have too much more trouble I may try using LISP despite having 2 days less and being somewhat unfamiliar with the language.

14-day Rougelike – Day I

This morning I was surfing around and stumbled across references to a mysterious 7DRL. After more research I discovered that this was an acronym for 7-day-rougelike. Where a person works on a rougelike for 7 days and then stops development. Entirely. Permanently. Thinking this was an interesting idea, I decided to have a go at a 14DRL, since this will be my first rougelike and first time using curses/ncurses for anything but tests.

I’m writing it in C using NCurses mainly as an exercise to keep my C skills (which have fallen into disusage) up as well as to learn the NCurses library better. The fact that it’s enjoyable helps too. So…today I got it to Display the map, display the player, move the player, display messages, and show stats. I am, however having trouble with collision detection. How do I get the contents of a cell in ncurses? Googling turned up nothing (well, lots of python). Should I just create an array on map generation containing all impassable cells and check that whenever the player moves? Anyway, I’ll put up sourcecode soon.

For starters…

For starters I’d like to thank David Crouse for all his work on the archlinux.us email addresses and now this blog site.

Funnily enough, right now I’m using Gentoo, not Arch. I still have an Arch install, but primarily I’m using Gentoo.

A little about my computer:

Intel Core 2 Quad Q6600 3.0Ghz
nVidia GeForce 8500
2GB mushkin RAM
640GB WD HDD
WIndows XPx64
Arch Linux
Gentoo Linux
Mac OS X (iDeneb) Leopard

Alright, so now a little about myself:

I’m a high-school student who is homeschooled in Kentucky, USA. I got into computers about 5 years ago when I got a book on HTML from the library. Over the past 5 years I have learned C/C++, Java, PHP, Javascript/HTML/CSS, Python, and bash scripting. By far my favorite is C++. I’m not sure why, I just enjoy writing C/C++ code.
Anyway, my dad does remodeling work around town, and sometimes I will work with him to make some money. One Mr. Chinque that we worked for found out about my interest in computers and recommended that I look into ‘Lie-nuex’ (as he properly pronounced it). Turns out he wrote ASM compilers in the late ’80s and early ’90s, so he knew what he was talking about. So, that’s how i got here. 3 years after trying Ubuntu 6.something-or-other.

I tried Gentoo before Arch, and my computer at the time was slow enough that I gave up before I finished the install. So, finding Arch also minimalist (and liking it’s init system better) I have had an installation of it for the  past year or so. I don’t ever anticipate that changing.

Thanks again Crouse!!