Added more rooms
authorLukas Krickl <lukaskrickl@gmail.com>
Sat, 20 Jan 2018 21:04:25 +0000 (22:04 +0100)
committerLukas Krickl <lukaskrickl@gmail.com>
Sat, 20 Jan 2018 21:04:25 +0000 (22:04 +0100)
12 files changed:
gfx/room01_pf0.png [new file with mode: 0644]
gfx/room01_pf0.spr [new file with mode: 0644]
gfx/room01_pf1.png [new file with mode: 0644]
gfx/room01_pf1.spr [new file with mode: 0644]
gfx/room01_pf2.png [new file with mode: 0644]
gfx/room01_pf2.spr [new file with mode: 0644]
main.asm
makefile
tools/png2bin/readme.md
tools/png2bin/src/imageconverter.cpp
tools/png2bin/src/include/imageconverter.h
tools/png2bin/src/util.cpp

diff --git a/gfx/room01_pf0.png b/gfx/room01_pf0.png
new file mode 100644 (file)
index 0000000..8ca1616
Binary files /dev/null and b/gfx/room01_pf0.png differ
diff --git a/gfx/room01_pf0.spr b/gfx/room01_pf0.spr
new file mode 100644 (file)
index 0000000..edb6935
--- /dev/null
@@ -0,0 +1,26 @@
+; Sprite of ../../gfx/room01_pf0.png
+.byte %000001111
+.byte %000000001
+.byte %000000001
+.byte %000000001
+.byte %000111001
+.byte %000001001
+.byte %000001001
+.byte %000000001
+.byte %000000001
+.byte %000000001
+.byte %010001001
+.byte %010001001
+.byte %000000001
+.byte %000000001
+.byte %000000001
+.byte %000001001
+.byte %000001001
+.byte %000111001
+.byte %000000001
+.byte %000000001
+.byte %000000001
+.byte %000000001
+.byte %000000001
+.byte %000001111
+
diff --git a/gfx/room01_pf1.png b/gfx/room01_pf1.png
new file mode 100644 (file)
index 0000000..f9db4f7
Binary files /dev/null and b/gfx/room01_pf1.png differ
diff --git a/gfx/room01_pf1.spr b/gfx/room01_pf1.spr
new file mode 100644 (file)
index 0000000..957740c
--- /dev/null
@@ -0,0 +1,26 @@
+; Sprite of ../../gfx/room01_pf1.png
+.byte %00000000
+.byte %00000000
+.byte %00000000
+.byte %00000000
+.byte %00111110
+.byte %00000010
+.byte %00000010
+.byte %00000010
+.byte %00000010
+.byte %00000010
+.byte %11111110
+.byte %11111110
+.byte %00000010
+.byte %00000010
+.byte %00000010
+.byte %00000010
+.byte %00000010
+.byte %00111110
+.byte %00000000
+.byte %00000000
+.byte %00000000
+.byte %00000000
+.byte %00000000
+.byte %00000000
+
diff --git a/gfx/room01_pf2.png b/gfx/room01_pf2.png
new file mode 100644 (file)
index 0000000..5453245
Binary files /dev/null and b/gfx/room01_pf2.png differ
diff --git a/gfx/room01_pf2.spr b/gfx/room01_pf2.spr
new file mode 100644 (file)
index 0000000..da32378
--- /dev/null
@@ -0,0 +1,26 @@
+; Sprite of ../../gfx/room01_pf2.png
+.byte %00000000
+.byte %00000000
+.byte %00111110
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00100000
+.byte %00111110
+.byte %00000000
+.byte %00000000
+.byte %00000000
+.byte %00000000
+
index 007a6ef6f158460e8994d3f00054b3ee3728f3a4..e8c43bb23677cd402835a5a9d2eb279cb45af390 100644 (file)
--- a/main.asm
+++ b/main.asm
@@ -99,7 +99,7 @@ P1STARTX = 0
 P1STARTY = 0
 M0HEIGHT = 4
 M0RESPAWNT = 255
-MAPCOUNT = 0
+MAPCOUNT = 1
 OFFSETPERMAP = 6
 
 ;===============================================================================
@@ -556,6 +556,7 @@ GameProgress
        jmp ProgressDone
 NextMapProg
        jsr NextMap
+       jsr ResetPPositions
        jmp ProgressDone
 NextLevelProg
        jsr NextLevel
@@ -814,6 +815,7 @@ NextMap
        lda #0
        ; now add 6 for each number rolled
 NextMapLoop
+       clc
        adc Temp
        dey
        bne NextMapLoop
@@ -1242,7 +1244,8 @@ DigitGfx:
 
 ; the room table holds pf information for each 1/2 scanline as a byte. 45 bytes
 ; All rooms require PF1 and PF2 tables as well
-Room1LayoutPF0:
+; Reminder that pf0 only uses 4 bits
+Room0LayoutPF0:
        .byte %11110000
        .byte %00010000
        .byte %00010000
@@ -1265,7 +1268,10 @@ Room1LayoutPF0:
        .byte %00010000
        .byte %00010000
        .byte %11110000
-Room1LayoutPF1:
+       .byte %11111111
+       .byte %11111111
+       .byte %11111111
+Room0LayoutPF1:
        .byte %11111111
        .byte %00000000
        .byte %00000000
@@ -1288,7 +1294,10 @@ Room1LayoutPF1:
        .byte %00000000
        .byte %00000000
        .byte %11111111
-Room1LayoutPF2:
+       .byte %11111111
+       .byte %11111111
+       .byte %11111111
+Room0LayoutPF2:
        .byte %11111111
        .byte %10000000
        .byte %00000000
@@ -1311,10 +1320,92 @@ Room1LayoutPF2:
        .byte %00000000
        .byte %10000000
        .byte %11111111
+       .byte %11111111
+       .byte %11111111
+       .byte %11111111
+
+Room1LayoutPF0
+       .byte %000001111
+       .byte %000000001
+       .byte %000000001
+       .byte %000000001
+       .byte %000111001
+       .byte %000001001
+       .byte %000001001
+       .byte %000000001
+       .byte %000000001
+       .byte %000000001
+       .byte %010001001
+       .byte %010001001
+       .byte %000000001
+       .byte %000000001
+       .byte %000000001
+       .byte %000001001
+       .byte %000001001
+       .byte %000111001
+       .byte %000000001
+       .byte %000000001
+       .byte %000000001
+       .byte %000000001
+       .byte %000000001
+       .byte %000001111
+Room1LayoutPF1
+       .byte %00000000
+       .byte %00000000
+       .byte %00000000
+       .byte %00000000
+       .byte %00111110
+       .byte %00000010
+       .byte %00000010
+       .byte %00000010
+       .byte %00000010
+       .byte %00000010
+       .byte %11111110
+       .byte %11111110
+       .byte %00000010
+       .byte %00000010
+       .byte %00000010
+       .byte %00000010
+       .byte %00000010
+       .byte %00111110
+       .byte %00000000
+       .byte %00000000
+       .byte %00000000
+       .byte %00000000
+       .byte %00000000
+       .byte %00000000
+Room1LayoutPF2
+       .byte %00000000
+       .byte %00000000
+       .byte %00111110
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00100000
+       .byte %00111110
+       .byte %00000000
+       .byte %00000000
+       .byte %00000000
+       .byte %00000000
 
 
 ; Table holding all the room start addresses next to each other
 RoomTable:
+       .word Room0LayoutPF0
+       .word Room0LayoutPF1
+       .word Room0LayoutPF2
        .word Room1LayoutPF0
        .word Room1LayoutPF1
        .word Room1LayoutPF2
index fbe0a2764439d13adb20bbee5aeb22d8a0ddfba5..ff01d456454b43cb46b48226a9462c10ae306233 100644 (file)
--- a/makefile
+++ b/makefile
@@ -1,5 +1,5 @@
 all:
-       dasm main.asm -f3 -v5 -o./bin/game.bin -l./bin/game.lst -s./bin/game.sym
+       dasm main.asm -f3 -v5 -o./bin/tb.bin -l./bin/tb.lst -s./bin/tb.sym
 
 clean:
        rm ./bin/*.bin
index ca654fde6ace2c839136255b8d105b95a579815a..7e92d66b44e9d0d36fca8c4451e779e5be16b904 100644 (file)
@@ -1,3 +1,3 @@
-This is a simple tool used to convert N by N sized images to byte arrays.
+This is a simple tool used to convert N by 8 sized images to byte arrays.
 I used it to simplify making sprites and maps.
-All images must be multiples of 8 in size!
+All images must be multiples of 8 in height!
index 3a38168b3aabd281e442c140d8e5322fc30bca40..2b3f12f0b57a4120f1152f05db304b44007b104f 100644 (file)
@@ -1,7 +1,7 @@
 #include"include/imageconverter.h"
 #include"include/colour.h"
 #include <exception>
-#include<string>
+#include <string>
 #include <sstream>
 #include <iomanip>
 #include <iostream>
@@ -30,19 +30,10 @@ namespace Image {
     x * width + y
     This simulates a 2d array with less of a memory mess
     */
-    this->converted = new unsigned int[image->get_width() * image->get_height()];
-    if(!this->converted) {
-      std::cerr << red << "[FATAL] " << def
-      << "Unable to allocate enough memory for converted image!" << std::endl;
-      exit(-1);
-    }
   }
 
   ImageConverter::~ImageConverter() {
     // TODO error when freeing
-    if(this->converted) {
-      delete[] this->converted;
-    }
 
     if(this->image) {
       delete this->image;
@@ -53,9 +44,10 @@ namespace Image {
     if(settings->verbose) {
       std::cout << "Converting pixels" << std::endl;
     }
-
-    for(int w = 0; w < this->image->get_width(); w++) {
-      for(int h = 0; h < this->image->get_height(); h++) {
+    converted.clear();
+    for(int h = 0; h < this->image->get_height(); h++) {
+      converted.emplace_back(std::vector<unsigned int>());
+      for(int w = 0; w < this->image->get_width(); w++) {
         png::rgb_pixel pixel = image->get_pixel(w, h);
 
         // converted pixel
@@ -100,6 +92,8 @@ namespace Image {
           std::cerr << "Pixel (" << w << "/" << h << ") "
           << red << "[WARNING] " << def << "Colour " << hexColour << " not found in list. Defaulting to 0 "
           << std::endl;
+
+          colourFound = 0;
         }
 
         if(settings->verbose) {
@@ -110,9 +104,9 @@ namespace Image {
           << (short)pixel.blue
           << " " << hexColour << std::endl;
         }
-        this->converted[w * image->get_width() + h] = pixelConverted;
+        converted[h].emplace_back(pixelConverted);
         if(settings->verbose) {
-          std::cout << "Set " << this->converted[w * image->get_width() + h] << "(" <<
+          std::cout << "Set " << converted[w][h] << "(" <<
           w * image->get_width() + h << "th element)\n\n";
         }
       }
@@ -121,33 +115,26 @@ namespace Image {
 
   void ImageConverter::writePixels() {
     std::ofstream outfile;
-
     outfile.open(settings->outfile);
-    if(settings->outputBase == "detailed") {
-      if(settings->verbose) std::cout << "Outputting sprite in detailed mode!\n";
-
-      // outputting to file
-      unsigned short stepCounter = image->get_width() / 8;
-      for(int sc = 0; sc < stepCounter; sc++) {
-        // each of these loops will write 8 by 8 pixels at most so we loop N times to get all arrays
-        outfile << "; Sprite of " << settings->inputfile << " Part " << sc << "/" << stepCounter << std::endl;
-        for(int x = 0; x < image->get_width(); x++) {
-          outfile << ".byte ";
-
-          for(int y = stepCounter * 8 - 8; y < 8 * stepCounter; y++) {
-            if(y < image->get_width()) {
-              outfile << converted[x * image->get_width() + y];
-            } else {
-              outfile << 0;
-            }
-          }
-          outfile << std::endl;
+
+    // outputting to file
+    outfile << "; Sprite of " << settings->inputfile << std::endl;
+    for(int x = 0; x < image->get_height(); x++) {
+      outfile << ".byte \%";
+      // pf0 is inverted!
+      if(settings->outputBase == "p0") {
+        for(int y = image->get_width(); y >= 0; y--) {
+          outfile << converted[x][y];
+        }
+      } else {
+        for(int y = 0; y < image->get_width(); y++) {
+          outfile << converted[x][y];
         }
-        outfile << std::endl;
       }
-
-      outfile << std::endl << std::endl;
+      outfile << std::endl;
     }
+    outfile << std::endl;
+
     outfile.close();
   }
 }
index ea4ada901b4948e8046f19598347699f28022a5b..4d219378979f5238d82206bca2dc08bb501cf8b5 100644 (file)
@@ -4,13 +4,14 @@
 #include<png++/png.hpp>
 #include<cstdint>
 #include"util.h"
+#include<vector>
 
 namespace Image {
   class ImageConverter {
   private:
     png::image<png::rgb_pixel> *image;
 
-    unsigned int *converted; // converted image for each pixel
+    std::vector<std::vector<unsigned int> > converted; // converted image for each pixel
 
     Settings *settings;
   public:
index 072000613a16bccc59359f534c23245abd5922a3..6425609edf4f005d1be70a46a53c479c0015aade 100644 (file)
@@ -22,12 +22,12 @@ void init() {
 
   // set default options
   globalsettings.appmode = "sprite";
-  globalsettings.outputBase = "detailed";
+  globalsettings.outputBase = "default";
   globalsettings.colours = (uint32_t*)malloc(5 * sizeof(uint32_t));
 
   // set default colour pallette
-  globalsettings.colours[0] = 0x000000;
-  globalsettings.colours[1] = 0xFFFFFF;
+  globalsettings.colours[0] = 0xFFFFFF;
+  globalsettings.colours[1] = 0x000000;
 
   globalsettings.coloursLen = 2;
 
@@ -57,7 +57,7 @@ void parseArgs(int argc, char **argv) {
       "-v\t(optional) Outputs version information\n" <<
       "-f ./example.png\t(required) Set the file that is to be converted\n" <<
       "-o ./output\t(optional) Set the output file and directory\n" <<
-      "-b detailed/compressed\t(optional) Set the base to output the data in (defaults to detailed)\n" <<
+      "-b p0/default\t(optional) Set the base to output the data in (defaults to detailed)\n" <<
       "verbose\t(optional) Verbose mode.";
     } else if(arg == "-f") {
       if(extraArgumentsNeeded(1, argc, index)) {
@@ -70,7 +70,7 @@ void parseArgs(int argc, char **argv) {
     } else if(arg == "-o") {
       if(extraArgumentsNeeded(1, argc, index)) {
         index++;
-        globalsettings.outfile = argv[index];
+        globalsettings.outfile = argv[index] + '\0';
       } else {
         std::cerr << red << "[FATAL]" << def << " Insufficent arguments: Use -h for syntax!" << std::endl;
         exit(-1);