public void loadWalls() { gb.BufferLocation = 0x50917; for (int i = 0; i < 9; i++) { byte b = 0; int count = 0; List <LAObject> listt = new List <LAObject>(); while ((b = gb.ReadByte()) != 0xFF) { LAObject t = new LAObject(); t.y = (byte)(b / 16); t.x = (byte)(b - (t.y * 16)); listt.Add(t); count++; } byte[] buffer = gb.ReadBytes(count); for (int k = 0; k < count; k++) { LAObject t = listt[k]; t.id = buffer[k]; listt[k] = t; wallTiles[i, k] = listt[k]; } } }
public Bitmap drawSelectedSprite(Image map, LAObject selected) { Bitmap b = (Bitmap)map; FastPixel fp = new FastPixel(b); fp.rgbValues = new byte[160 * 128 * 4]; fp.Lock(); if (selected.x > 9 || selected.y > 7) { fp.Unlock(true); return(b); } for (int yy = 0; yy < 16; yy++) { for (int xx = 0; xx < 16; xx++) { int x = selected.x * 16; int y = selected.y * 16; if (xx == 0 || xx == 15) { if (xx == 0) { // fp.SetPixel(x + (xx - 1), y + yy, Color.White); fp.SetPixel(x + xx, y + yy, Color.White); } else if (xx == 15) { // fp.SetPixel(x + (xx + 1), y + yy, Color.White); fp.SetPixel(x + xx, y + yy, Color.White); } } else { if (yy == 0) { // fp.SetPixel(x + xx, y + (yy - 1), Color.White); fp.SetPixel(x + xx, y + yy, Color.White); // if (xx == 0) // fp.SetPixel(x + (xx - 1), y + yy, Color.White); // else if (xx == 15) // fp.SetPixel(x + (xx + 1), y + yy, Color.White); } else if (yy == 15) { // fp.SetPixel(x + xx, y + (yy + 1), Color.White); fp.SetPixel(x + xx, y + yy, Color.White); // if (xx == 0) // fp.SetPixel(x + (xx - 1), y + yy, Color.White); // else if (xx == 15) // fp.SetPixel(x + (xx + 1), y + yy, Color.White); } } } } fp.Unlock(true); return(b); }
private void nObjectID_ValueChanged(object sender, EventArgs e) { O.id = (byte)nObjectID.Value; O.gb = gb; if (overworld) { O = O.getOverworldSpecial(O); } else { O = O.dungeonDoors(O); } }
public void loadObjects(bool overworld, byte dungeon, byte map) { spriteList = new List <LAObject>(); if (overworld) { gb.BufferLocation = 0x58000; } else { gb.BufferLocation = 0x58200; if (dungeon >= 6 && dungeon < 0x1A) { gb.BufferLocation = 0x58400; } else if (dungeon == 0xFF) { gb.BufferLocation = 0x58600; } } gb.BufferLocation = gb.Get3BytePointerAddress((byte)(gb.BufferLocation / 0x4000), gb.BufferLocation + (map * 2)).Address; objectAddress = gb.BufferLocation; byte b; while ((b = gb.ReadByte()) != 0xFF) //0xFE = End of room { LAObject ob = new LAObject(); // 2-Byte tiles ob.y = (byte)(b >> 4); ob.x = (byte)(b & 0xF); ob.id = gb.ReadByte(); spriteList.Add(ob); } spriteData = new byte[80]; foreach (LAObject obj in spriteList) { if (obj.y < 0 || obj.y > 7) { continue; } if (obj.x < 0 || obj.x > 9) { continue; } spriteData[obj.x + (obj.y * 10)] = (byte)obj.id; } }
public Bitmap drawSelectedObject(Bitmap image, LAObject selected) { Color border = Color.White; FastPixel fp = new FastPixel(image); fp.rgbValues = new byte[160 * 128 * 4]; fp.Lock(); foreach (LAObject obj in objects) { if (obj.x != selected.x) { continue; } if (obj.y != selected.y) { continue; } if (obj.direction != selected.direction) { continue; } if (obj.length != selected.length) { continue; } if (obj.id != selected.id) { continue; } int x = obj.x * 16; int y = obj.y * 16; if (obj.hFlip) { x = -16; } if (obj.vFlip) { y = -16; } bool v = false; bool h = false; if (!obj.is3Byte) { if (obj.x > 9 || obj.y > 7) { continue; } } if (!obj.is3Byte) { if (obj.isEntrance || obj.isDoor1 || obj.isDoor2) { for (int yy = 0; yy < obj.h * 16; yy++) { for (int xx = 0; xx < obj.w * 16; xx++) { if (x < 0 && !h) { xx = xx + 16; h = true; } if (y < 0 && !v) { yy = yy + 16; v = true; } if (x + xx >= 160 || x + xx < 0) { continue; } if (y + yy >= 128 || y + yy < 0) { continue; } if (yy > 0 && yy != ((obj.h * 16) - 1)) { if (xx == 0 || xx == (obj.w * 16) - 1) { fp.SetPixel(x + xx, y + yy, border); } } else { fp.SetPixel(x + xx, y + yy, border); } } } } else { for (int yy = 0; yy < 16; yy++) { for (int xx = 0; xx < 16; xx++) { if (yy > 0 && yy != 15) { if (xx == 0 || xx == 15) { fp.SetPixel(x + xx, y + yy, border); } } else { fp.SetPixel(x + xx, y + yy, border); } } } } } else { if (!obj.isDoor1 || !obj.isDoor2 || !obj.isEntrance) { if (obj.direction == 8) { for (int yy = 0; yy < 16; yy++) { for (int xx = 0; xx < (obj.length * 16); xx++) { if (x < 0 && !h) { xx = xx + 16; h = true; } if (y < 0 && !v) { yy = yy + 16; v = true; } if (x + xx >= 160 || x + xx < 0) { continue; } if (y + yy >= 128 || y + yy < 0) { continue; } if (yy > 0 && yy != 15) { if (xx == 0 || xx == (obj.length * 16) - 1) { fp.SetPixel(x + xx, y + yy, border); } } else { fp.SetPixel(x + xx, y + yy, border); } } } } else { for (int yy = 0; yy < obj.length * 16; yy++) { for (int xx = 0; xx < 16; xx++) { if (x < 0 && !h) { xx = xx + 16; h = true; } if (y < 0 && !v) { yy = yy + 16; v = true; } if (x + xx >= 160 || x + xx < 0) { continue; } if (y + yy >= 128 || y + yy < 0) { continue; } if (yy > 0 && yy != (obj.length * 16) - 1) { if (xx == 0 || xx == 15) { fp.SetPixel(x + xx, y + yy, border); } } else { fp.SetPixel(x + xx, y + yy, border); } } } } } else { if (obj.direction == 8) { for (int i = 0; i < obj.length; i++) { for (int yy = 0; yy < obj.h * 16; yy++) { for (int xx = 0 + (i * 16); xx < obj.w * (obj.length * 16); xx++) { if (x < 0 && !h) { xx = xx + 16; h = true; } if (y < 0 && !v) { yy = yy + 16; v = true; } if (x + xx >= 160 || x + xx < 0) { continue; } if (y + yy >= 128 || y + yy < 0) { continue; } if (yy > 0 && yy != ((obj.h * 16) - 1)) { if (xx == 0 || xx == ((obj.length * 16) * obj.w) - 1) { fp.SetPixel(x + xx, y + yy, border); } } else { fp.SetPixel(x + xx, y + yy, border); } } } } } else { for (int i = 0; i < obj.length; i++) { for (int yy = 0 + (i * 16); yy < obj.h * (obj.length * 16); yy++) { for (int xx = 0; xx < obj.w * 16; xx++) { if (x < 0 && !h) { xx = xx + 16; h = true; } if (y < 0 && !v) { yy = yy + 16; v = true; } if (x + xx >= 160 || x + xx < 0) { continue; } if (y + yy >= 128 || y + yy < 0) { continue; } if (yy > 0 && yy != ((obj.length * 16) * obj.h) - 1) { if (xx == 0 || xx == obj.w * 16) { fp.SetPixel(x + xx, y + yy, border); } } else { fp.SetPixel(x + xx, y + yy, border); } } } } } } } } fp.Unlock(true); return(image); }
public void getCollisionDataDungeon(byte map, byte dungeon, bool magGlass) { objects = new List <LAObject>(); warps = new List <Warps>(); if (magGlass && map == 0xF5 && dungeon >= 0x1A || magGlass && map == 0xF5 && dungeon < 6) { gb.BufferLocation = gb.Get2BytePointerAddress(0x3198).Address; gb.BufferLocation += 0x28001; } else { gb.BufferLocation = 0x28000; if (dungeon >= 6 && dungeon < 0x1A) { gb.BufferLocation += 0x4000; } else if (dungeon == 0xFF) { gb.BufferLocation = 0x2BB77; } gb.BufferLocation = gb.Get3BytePointerAddress((byte)(gb.BufferLocation / 0x4000), gb.BufferLocation + (map * 2)).Address + 1; //skip animation } mapAddress = gb.BufferLocation - 1; byte b = gb.ReadByte(); while ((b = gb.ReadByte()) != 0xFE) //0xFE = End of room { if (b >> 4 == 0xE) { Warps w = new Warps(); w.type = (byte)(b & 0x0F); w.region = gb.ReadByte(); w.map = gb.ReadByte(); w.x = gb.ReadByte(); w.y = gb.ReadByte(); warps.Add(w); continue; } if (b >> 4 == 8 || b >> 4 == 0xC) //3-Byte objects { LAObject o = new LAObject(); o.is3Byte = true; o.length = (byte)(b & 0xF); o.direction = (byte)(b >> 4); byte b2 = gb.ReadByte(); o.y = (byte)(b2 >> 4); o.x = (byte)(b2 & 0xF); o.id = gb.ReadByte(); objects.Add(o); continue; } LAObject ob = new LAObject(); // 2-Byte tiles ob.y = (byte)(b >> 4); ob.x = (byte)(b & 0xF); ob.id = gb.ReadByte(); if (ob.id >= 0xEC && ob.id <= 0xFD)// Door tiles { int bufferloc = gb.BufferLocation; ob.gb = gb; ob = ob.dungeonDoors(ob); gb.BufferLocation = bufferloc; } objects.Add(ob); } }
public void loadCollisionsDungeon() { data = new byte[80]; for (int i = 0; i < 80; i++) { data[i] = floor; } for (int i = 0; i < 64; i++) { LAObject o = wallTiles[wall, i]; if (o != null) { data[o.x + (o.y * 10)] = (byte)o.id; } } foreach (LAObject obj in objects) { byte door = obj.id; int dx = (obj.x == 0xF ? (obj.x - 16) : obj.x); int dy = (obj.y == 0xF ? (obj.y - 16) : obj.y); if (!obj.is3Byte && !obj.isDoor1 && !obj.isDoor2 && !obj.isEntrance) { if (dy < 0 || dy > 7) { continue; } if (dx < 0 || dx > 9) { continue; } data[obj.x + (obj.y * 10)] = (byte)obj.id; } else if (obj.is3Byte) { for (int i = 0; i < obj.length; i++) { if (obj.direction == 8) //horizontal { if (dy > 7 || dy < 0) { continue; } if (dx < 0) { dx++; obj.x = 0; i++; } if (dx > 10) { continue; } if (obj.x + (obj.y * 10) + i >= 80) { continue; } data[obj.x + (obj.y * 10) + i] = obj.id; dx++; } else { if (dx > 9) { continue; } if (dy < 0) { dy++; obj.y = 0; i++; } if (dy > 7) { continue; } if (obj.x + (obj.y * 10) + (i * 10) >= 80) { continue; } data[obj.x + (obj.y * 10) + (i * 10)] = obj.id; dy++; } } } else if (obj.isDoor1) { obj.w = 2; obj.h = 1; for (int i = 0; i < 2; i++) { if (dx < 0) { dx++; obj.x = 0; i++; } if (dx > 9) { continue; } if (dy > 7) { continue; } if ((obj.x + i) + (obj.y * 10) >= 80) { continue; } obj.id = obj.tiles[i]; data[(obj.x + i) + (obj.y * 10)] = (byte)obj.id; dx++; } obj.id = door; } else if (obj.isDoor2) { obj.h = 2; obj.w = 1; for (int i = 0; i < 2; i++) { if (dy < 0) { dy++; obj.y = 0; i++; } if (dy > 7) { continue; } if (dx > 9) { continue; } if (obj.x + ((obj.y + i) * 10) >= 80) { continue; } obj.id = obj.tiles[i]; data[obj.x + ((obj.y + i) * 10)] = obj.id; dy++; } obj.id = door; } else if (obj.isEntrance) { int i = 0; for (int y = 0; y < 3; y++) { for (int x = 0; x < 4; x++) { if (dy < 0) { dy++; obj.y = 0; i++; } if (dy > 7) { continue; } if (dx < 0) { dx++; obj.x = 0; i++; } if (dx > 9) { continue; } if ((obj.x + x) + ((obj.y + y) * 10) >= 80) { continue; } obj.id = obj.tiles[i]; data[(obj.x + x) + ((obj.y + y) * 10)] = (byte)obj.id; i++; dx++; if (x == 3) { dy++; dx = obj.x; } } } obj.id = door; } } }
public void getOverworldObjs(LAObject objects) { LAObject O = new LAObject(); switch (objects.id) { case 0xF5: { O.tiles = new byte[] { 0x25, 0x26, 0x27, 0x28 }; O.w = 2; O.h = 2; O.special = true; break; } case 0xF6: { O.tiles = new byte[] { 85, 90, 90, 90, 86, 87, 89, 89, 89, 88, 91, 226, 91, 226, 91 }; O.w = 5; O.h = 3; O.special = true; break; } case 0xF7: // House { O.tiles = new byte[] { 85, 90, 86, 87, 89, 88, 91, 226, 91 }; O.w = 3; O.h = 3; O.special = true; break; } case 0xF8: //Catfish's Maw { O.tiles = new byte[] { 0xB6, 0xB7, 0x66, 0x67, 0xE3, 0x68 }; O.w = 3; O.h = 2; O.special = true; break; } case 0xF9: //Palace Doors { O.tiles = new byte[] { 0xA4, 0xA5, 0xA6, 0xA7, 0xE3, 0xA8 }; O.w = 3; O.h = 2; O.special = true; break; } case 0xFA: { O.tiles = new byte[] { 187, 188, 189, 190 }; O.w = 2; O.h = 2; O.special = true; break; } case 0xFB: { O.tiles = new byte[] { 182, 183, 205, 206 }; O.w = 2; O.h = 2; O.special = true; break; } case 0xFC: { O.tiles = new byte[] { 43, 44, 45, 55, 232, 56, 51, 224, 52 }; O.w = 3; O.h = 3; O.special = true; break; } case 0xFD: { O.tiles = new byte[] { 82, 82, 82, 91, 226, 91 }; O.w = 3; O.h = 2; O.special = true; break; } } if (objects.is3Byte) { O.length = objects.length; O.direction = objects.direction; O.is3Byte = true; } if (objects.x == 0xF) { O.hFlip = true; } if (objects.y == 0xF) { O.vFlip = true; } O.id = objects.id; O.x = objects.x; O.y = objects.y; objectIDs.Add(O); }
public LAObject dungeonDoors(LAObject ob) { int door = ob.id; int y1 = ob.y; int x1 = ob.x; byte[] tiles; switch (door) { case 0xEC: gb.BufferLocation = 0x35EF; break; // Key Doors case 0xED: gb.BufferLocation = 0x360A; break; case 0xEE: gb.BufferLocation = 0x3625; break; case 0xEF: gb.BufferLocation = 0x3640; break; case 0xF4: gb.BufferLocation = 0x36A7; break; // Open Doors case 0xF5: gb.BufferLocation = 0x36DF; break; case 0xF6: gb.BufferLocation = 0x36F3; break; case 0xF7: gb.BufferLocation = 0x3707; break; case 0xF0: gb.BufferLocation = 0x36A7; break; // Closed Doors case 0xF1: gb.BufferLocation = 0x36DF; break; case 0xF2: gb.BufferLocation = 0x36F3; break; case 0xF3: gb.BufferLocation = 0x3707; break; case 0xF8: gb.BufferLocation = 0x371B; break; // Boss Door case 0xF9: gb.BufferLocation = 0x3753; break; // ?? Stairs maybe case 0xFA: gb.BufferLocation = 0x3762; break; // FLip Wall case 0xFB: gb.BufferLocation = 0x3771; break; // One-way Arrow case 0xFC: gb.BufferLocation = 0x378D; break; // Dungeon Entrances case 0xFD: gb.BufferLocation = 0x37AB; break; //Indoor Entrances } if (door == 0xEC || door == 0xED || door == 0xF0 || door == 0xF1 || door == 0xF4 || door == 0xF5 || door == 0xF8 || door == 0xFA || door == 0xFB || door == 0xFD) { tiles = new byte[2]; ob.isDoor1 = true; ob.isDoor2 = false; ob.isEntrance = false; ob.w = 2; ob.h = 1; ob.tiles = tiles; ob.y = (byte)y1; ob.x = (byte)x1; for (int i = 0; i < 2; i++) { tiles[i] = gb.ReadByte(); } ob.id = (byte)door; //objects.Add(ob); } else if (door == 0xEE || door == 0xEF || door == 0xF2 || door == 0xF3 || door == 0xF6 || door == 0xF7) { tiles = new byte[2]; ob.isDoor2 = true; ob.isEntrance = false; ob.isDoor1 = false; ob.w = 1; ob.h = 2; ob.tiles = tiles; ob.x = (byte)x1; ob.y = (byte)y1; for (int i = 0; i < 2; i++) { tiles[i] = gb.ReadByte(); } ob.id = (byte)door; //objects.Add(ob); } else if (door == 0xFC)//Dungeon entrance { tiles = new byte[13]; ob.tiles = tiles; ob.isEntrance = true; ob.isDoor1 = false; ob.isDoor2 = false; ob.w = 4; ob.h = 3; for (int i = 0; i < 13; i++) { tiles[i] = gb.ReadByte(); } ob.id = (byte)door; //objects.Add(ob); } return(ob); }