Topic:   iPhone Project: Enlisting Map Creators   (Read 234835 times)


0 Members and 1 Guest are viewing this topic.

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: iPhone Project: Enlisting Map Creators
« Reply #180 on: April 11, 2010, 01:44:53 PM »
Oh right, I get it. Hope it goes well. :)
I survived the spammage of 2007

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: iPhone Project: Enlisting Map Creators
« Reply #181 on: April 11, 2010, 04:51:18 PM »
Here's the AI code I need to reprogram to work with scrollable maps and in the World Editor:
Code: [Select]
- (void) moveNpc:(NpcData*)npcToProcess currentMapTiles:(NSArray*)tiles allNpcs:(NSArray*)allNpcs {
int target = npcToProcess.target;
CGPoint npcTilePosition = npcToProcess.position;
TileData* npcTile = [[tiles objectAtIndex:npcTilePosition.x] objectAtIndex:npcTilePosition.y];
if (target == -1) //RANDOM
{
int vertOrHorz = arc4random() % 2;
int moveDirection = arc4random() % 2;
if (moveDirection == 0) {moveDirection = -1;}
if (vertOrHorz == 0) { //Vertical
if (npcTilePosition.y + moveDirection >= 0 && npcTilePosition.y + moveDirection < [[tiles objectAtIndex:0] count]) {
TileData *tileToGo = [[tiles objectAtIndex:npcTilePosition.x] objectAtIndex:npcTilePosition.y + moveDirection];
if (tileToGo.npcOn==0 && tileToGo.blocked==0 && (playerData.playerTilePos.x != npcTilePosition.x || playerData.playerTilePos.y != npcTilePosition.y + moveDirection)) {
npcTilePosition.y += moveDirection;
}
}
} else { //Horizontal
if (npcTilePosition.x + moveDirection >= 0 && npcTilePosition.x + moveDirection < [tiles count]) {
TileData *tileToGo = [[tiles objectAtIndex:npcTilePosition.x + moveDirection] objectAtIndex:npcTilePosition.y];
if (tileToGo.npcOn==0 && tileToGo.blocked==0 && (playerData.playerTilePos.x != npcTilePosition.x + moveDirection || playerData.playerTilePos.y != npcTilePosition.y)) {
npcTilePosition.x += moveDirection;
}
}
}
} else //Move towards target
{
CGPoint targetPos;
if (target == -2) {targetPos = playerData.playerTilePos;} else {
NpcData* npcTarget = [allNpcs objectAtIndex:target];
targetPos = npcTarget.position;}
TileData* tilesAround[4] = {nil, nil, nil, nil}; //Up down left right
if (npcTilePosition.y > 0) {tilesAround[0] = [[tiles objectAtIndex:npcTilePosition.x] objectAtIndex:npcTilePosition.y - 1];}
if (npcTilePosition.y < 6) {tilesAround[1] = [[tiles objectAtIndex:npcTilePosition.x] objectAtIndex:npcTilePosition.y + 1];}
if (npcTilePosition.x > 0) {tilesAround[2] = [[tiles objectAtIndex:npcTilePosition.x - 1] objectAtIndex:npcTilePosition.y];}
if (npcTilePosition.x < 7) {tilesAround[3] = [[tiles objectAtIndex:npcTilePosition.x + 1] objectAtIndex:npcTilePosition.y];}
BOOL moveableDirections[4] = {YES, YES, YES, YES}; //Up down left right
if (tilesAround[0] == nil) {moveableDirections[0] = NO;}
if (tilesAround[1] == nil) {moveableDirections[1] = NO;}
if (tilesAround[2] == nil) {moveableDirections[2] = NO;}
if (tilesAround[3] == nil) {moveableDirections[3] = NO;}

//Place in movement restrictions
CGPoint playerPos = playerData.playerTilePos;
if (playerPos.x == npcTilePosition.x && playerPos.y == npcTilePosition.y - 1) {moveableDirections[0] = NO;}
if (playerPos.x == npcTilePosition.x && playerPos.y == npcTilePosition.y + 1) {moveableDirections[1] = NO;}
if (playerPos.x == npcTilePosition.x - 1 && playerPos.y == npcTilePosition.y) {moveableDirections[2] = NO;}
if (playerPos.x == npcTilePosition.x + 1 && playerPos.y == npcTilePosition.y) {moveableDirections[3] = NO;}

if (moveableDirections[0]) {moveableDirections[0] = !(tilesAround[0].blocked==1 || tilesAround[0].npcOn==1);}
if (moveableDirections[1]) {moveableDirections[1] = !(tilesAround[1].blocked==1 || tilesAround[1].npcOn==1);}
if (moveableDirections[2]) {moveableDirections[2] = !(tilesAround[2].blocked==1 || tilesAround[2].npcOn==1);}
if (moveableDirections[3]) {moveableDirections[3] = !(tilesAround[3].blocked==1 || tilesAround[3].npcOn==1);}


Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: iPhone Project: Enlisting Map Creators
« Reply #182 on: April 11, 2010, 04:51:37 PM »
Code: [Select]
//Aim to move towards player, if can't, move randomly
BOOL ablemovetotargetx = (targetPos.x < npcTilePosition.x && moveableDirections[2])||(targetPos.x > npcTilePosition.x && moveableDirections[3]);
BOOL ablemovetotargety = (targetPos.y < npcTilePosition.y && moveableDirections[0])||(targetPos.y > npcTilePosition.y && moveableDirections[1]);
int movedir = -1; // 0 = x, 1 = y
if (ablemovetotargetx && ablemovetotargety) {movedir = arc4random() % 2;}
else if (ablemovetotargetx) {movedir = 0;} else if (ablemovetotargety) {movedir = 1;}

if (movedir == 0) {
if (targetPos.x < npcTilePosition.x && moveableDirections[2]) {npcTilePosition.x -= 1;}
if (targetPos.x > npcTilePosition.x && moveableDirections[3]) {npcTilePosition.x += 1;}
} else if (movedir == 1) {
if (targetPos.y < npcTilePosition.y && moveableDirections[0]) {npcTilePosition.y -= 1;}
if (targetPos.y > npcTilePosition.y && moveableDirections[1]) {npcTilePosition.y += 1;}
} else  //Move randomly as to get around barrier
if (!(abs(targetPos.x - npcTilePosition.x) <= 1 && abs(targetPos.y - npcTilePosition.y) == 0) && !(abs(targetPos.x - npcTilePosition.x) == 0 && abs(targetPos.y - npcTilePosition.y) <= 1)) {
int vertOrHorz = arc4random() % 2;
int moveDirection = arc4random() % 2;
if (moveDirection == 0) {moveDirection = -1;}
if (vertOrHorz == 0) { //Vertical
if (npcTilePosition.y + moveDirection >= 0 && npcTilePosition.y + moveDirection < [[tiles objectAtIndex:0] count]) {
TileData *tileToGo = [[tiles objectAtIndex:npcTilePosition.x] objectAtIndex:npcTilePosition.y + moveDirection];
if (tileToGo.npcOn==0 && tileToGo.blocked==0 && (playerData.playerTilePos.x != npcTilePosition.x || playerData.playerTilePos.y != npcTilePosition.y + moveDirection)) {
npcTilePosition.y += moveDirection;
}
}
} else { //Horizontal
if (npcTilePosition.x + moveDirection >= 0 && npcTilePosition.x + moveDirection < [tiles count]) {
TileData *tileToGo = [[tiles objectAtIndex:npcTilePosition.x + moveDirection] objectAtIndex:npcTilePosition.y];
if (tileToGo.npcOn==0 && tileToGo.blocked==0 && (playerData.playerTilePos.x != npcTilePosition.x + moveDirection || playerData.playerTilePos.y != npcTilePosition.y)) {
npcTilePosition.x += moveDirection;
}
}
}
}
}
npcTile.npcOn = 0;
TileData *nowOn = [[tiles objectAtIndex:npcTilePosition.x] objectAtIndex:npcTilePosition.y];
nowOn.npcOn = 1;
npcToProcess.position = npcTilePosition;
}

Piece of cake, no?


-Gan
« Last Edit: April 11, 2010, 04:54:33 PM by Gandolf »

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: iPhone Project: Enlisting Map Creators
« Reply #183 on: April 11, 2010, 05:31:27 PM »
Certainly looks impressive, but I can't stand un-tabbed code. Tab, tab, tab I say!

I've actually become slightly too rigorous with HTML and JS now though. Most objects are commonly typed on 1 line like so:

Code: [Select]
<img name="subNav3BackgroundButtonImg"src="images/subNav3Background.gif" alt="Designs"width="105"height="44">

But I tab everything:

Code: [Select]
<img
 Â   name="subNav3BackgroundButtonImg"
 Â   src="images/subNav3Background.gif"
 Â   alt="Designs"
 Â   width="105"
 Â   height="44"
>

It's really easy to recognise objects at a glance though. :)
« Last Edit: April 11, 2010, 05:33:07 PM by Silverwind »
I survived the spammage of 2007

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: iPhone Project: Enlisting Map Creators
« Reply #184 on: April 11, 2010, 05:36:45 PM »
Ahah, no worries. It is tabbed. When I copy it out of Xcode it untabs and changes the syntax highlight to one color.


-Gan

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: iPhone Project: Enlisting Map Creators
« Reply #185 on: April 11, 2010, 05:41:24 PM »
Ah... I should've copped that. The same thing happened when I posted my own example. ::)
I survived the spammage of 2007

Gnome


  • GMG Extraordinaire

  • ***


  • Posts: 1073
Re: iPhone Project: Enlisting Map Creators
« Reply #186 on: April 13, 2010, 10:01:00 PM »
I think I have most of the forest maps down. Maybe another side quest or two.

Side Quest 1- Destroyed town.


Forest Dungeon 1: Teh Forest (chest TBA)


Forest Dungeon 2: Goblin Camp (Fire pits TBA)
This Cannot be, NOOOOOOOO!!!!

-Gnomes Cry when the McRib was discontinued again.

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: iPhone Project: Enlisting Map Creators
« Reply #187 on: April 14, 2010, 10:54:33 AM »
Those look amazing! Last weekend was awful, but I will have less work this week, so I should be able to crank out some more tiles.

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: iPhone Project: Enlisting Map Creators
« Reply #188 on: April 14, 2010, 12:52:45 PM »
Oh indeed? Well check your PM box, last week I sent you a query concerning snow tiles.
I survived the spammage of 2007

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: iPhone Project: Enlisting Map Creators
« Reply #189 on: April 14, 2010, 02:46:42 PM »
Sorry about that, I just replied.

Gnome


  • GMG Extraordinaire

  • ***


  • Posts: 1073
Re: iPhone Project: Enlisting Map Creators
« Reply #190 on: April 20, 2010, 10:34:34 PM »
hehe, well I didn't want to bother WH on tiles we'd only need for one quest, so I appemted to make my own mana pool for the lightning trinket quest...

hehehe
This Cannot be, NOOOOOOOO!!!!

-Gnomes Cry when the McRib was discontinued again.

Silverwind


  • ^ This guy is amazing.

  • ****


  • Posts: 2805

  • For the glory of my maker
Re: iPhone Project: Enlisting Map Creators
« Reply #191 on: April 21, 2010, 03:22:48 AM »
Cool. :)
I survived the spammage of 2007

WarHampster


  • GMG Extraordinaire

  • ***


  • Posts: 1501

  • The People's Moderator
    • Arcade of the Absurd
Re: iPhone Project: Enlisting Map Creators
« Reply #192 on: April 21, 2010, 05:51:52 AM »
Nice, but why are the side and top tiles darker?

Gan


  • Administrator

  • ^ This guy is amazing.

  • *****


  • Posts: 4411
Re: iPhone Project: Enlisting Map Creators
« Reply #193 on: April 21, 2010, 08:24:03 AM »
This looks interesting... :)



-Gan

Gnome


  • GMG Extraordinaire

  • ***


  • Posts: 1073
Re: iPhone Project: Enlisting Map Creators
« Reply #194 on: April 21, 2010, 04:41:33 PM »
Quote
Nice, but why are the side and top tiles darker?


Its more of a joke on how bad i think they turned out. I'm going to fx it later.
This Cannot be, NOOOOOOOO!!!!

-Gnomes Cry when the McRib was discontinued again.