View Full Version : What now?
So far all i have made is a board game that stores piece location in an array board[8][10]
what should i try to make now? somthing that isn't a board game, id like to try something with movment.
oh yea, all i know is cocoa.
Najdorf
2005.01.22, 05:46 PM
make a chess AI. Its pretty challenging but should not tale more than 400 lines of code for a recursive brute force point algorithm.
sealfin
2005.01.22, 05:46 PM
I'd assume that you're looking to build on the abilities you've gained developing the board game, so why not try something with a foundation in arrays, a Pac Man or Rogue-alike maze/dungeon crawler?
Problem is i dont have the knowledge to do any of that:( I have no idea how to detect colisions, get keydown events, or contol the speed of a moving character. pretty much i know how to draw an image to an NSRect. thats about it. I guess id have to use timers to control speed? Thats the extent of my knowledge. Its very annoying not knowing very much :mad: :mad: :mad: :mad:
sealfin
2005.01.22, 06:27 PM
Well, a Rogue-alike (search for it, there's plenty of clones online) game is typically text-based (not a text adventure), and only runs through the event loop in response to the player pressing a key, and collision detection is limited to checking if a position on the map (which could easily be implemented as a 2D array) is occupied.
Otherwise, I'd suggest you learn a API more suited to games like SDL (http://www.libsdl.org/).
I tryed to learn SDL about 3 months ago, i failed because the only things i could find were a mailing list about things way more dificult to understand than i was ready for. And 3 tutorials from 3DCone or some place like that, but i didnt understand bliting at all, so when i learned how to draw to a rect in cocoa i decided to stay with that because it seemed a ton easier.
do you know of a peticularly good source/s for learning it?
Duane
2005.01.22, 08:29 PM
libsdl.org
click on tutorials
google "SDL tutorials"
etc, etc.
why doesn't this work?
NSRect tileArray[7][7];
and if it did would this work?
//setting locations of tiles
int locationX, locationY = 0;
int x, y;
for (x=0;x<48;x++) {
for (y=0;y<48;y++) {
tileArray[x][y] = NSMakeRect(locationX, locationY, 32, 32);
locationX += 32;
if (x == 6 || x == 13 || x == 20 || x == 27 || x == 34 ||x == 41 || x == 48) {
locationY += 32;
locationX = 0;
}
}
}
}
seven
2005.01.23, 12:58 AM
In your method you are trying to access memory at locations bigger than your array memory is allocated. Try shortening your for loops to max out at "6" instead of "48".
HTH.
Ok real question:
I am going to try to make the rouge clone that you suggested.
to test the arrays i am going to fill the 7x7 board with the "gold" image
here is my header
#import <Cocoa/Cocoa.h>
enum {WALL, ENEMY, HERO, GROUND, GOLD};
@interface dungeonView : NSView
{
int board[7][7];
NSRect tileArray[7][7];
NSImage *goldImage;
}
@end
and here is the section that loads GOLD into every space in board
int x, y;
for (x = 0 ; x < 7 ; x++) {
for (y = 0 ; y < 7 ; y++) {
board[x][y] = GOLD;
}
}
im pretty sure that works
here is the part that places the rects around the screen im pretty sure that doesnt work
what i want is the bottom left to be tileArray[0][0] and a column to the left to be tileArray[0][1]; one row up will be tileArray[1][1].
int xpos, ypos = 0;
for (x = 0 ; x < 7 ; x++) {
for (y = 0 ; y < 7 ; y++) {
tileArray[x][y] = NSMakeRect(xpos , ypos, 32, 32);
xpos += 32;
if (x == 6) {
ypos += 32;
xpos = 0;
}
}
}
}
now here is the drawing part in the drawRect method
- (void)drawRect:(NSRect)rect
{
NSRect modal;
modal.origin = NSZeroPoint;
int x, y;
for (x = 0 ; x < 7 ; x++) {
for (y = 0 ; y < 7 ; y++) {
switch (board[x][y]) {
case GOLD:
[NSBezierPath strokeRect:tileArray[x][y]];
modal.size = [goldImage size];
[goldImage drawInRect:tileArray[x][y] fromRect:modal operation:NSCompositeSourceOver fraction:1];
break;
}
}
}
}
it gets this werid column on the left side of the view with 6 drawn gold squares, not starting in the bottom left
what should my loop look like?
vBulletin® v3.6.8, Copyright ©2000-2008, Jelsoft Enterprises Ltd.