RPG game + LED pixel game system hardware

Post here to let others know of a project you're working on.

Moderators: Chuckt, Garth, bitfogav

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Tue Oct 16, 2012 10:05 pm

Wow, that seems really - really annoying!

Can I tempt you into using basic and a pic microcontroller :) The code is much nicer to play with and you don't have all these annoying things that arduino seems to have.

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Tue Oct 16, 2012 10:22 pm

Not for this project, not after I made all this code. For the next project, you might be able to tempt me though. So all you have to do is define it as const?
Last edited by Saimaster13 on Wed Oct 17, 2012 4:32 am, edited 1 time in total.
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Wed Oct 17, 2012 1:17 am

I got it! Thank you, Arduino forums.

It is a whole lot easier in only one dimension, so I just did that and made a little code to switch between the maps.

Anyway, to store a variable in flash, first you have to declare it:


Code: Select all

const prog_uint32_t MAPGreen3[97] PROGMEM = { 0, 1, whatever numbers you want};
The const is not actually needed but doesn't hurt (or do anything.)
prog_unint32_t is PROGMEM's unsigned long variable declaration, be sure to use the PROGMEM version if there is one (check the Arduino PROGMEM website for more special variables)
MAPGreen3 is my sting name, and it has 97 different numbers
PROGMEM can either come before or after everything to work. (I did after, there is no difference though)


The variable is now declared, but you will probably want to use or retrieve it in your code:

Code: Select all

pgm_read_dword(&MAPGreen2[x])
Writing that would be the same as writing "MAPGreen2[x]" if the variable was stored in RAM.
pgm_read_variableType(&variable) is the format
The "dword" variable type is 4 bytes, there is also 2 bytes "word" and 1byte "byte" (there might also be char, I'm not sure)
Remember the &
Write the string or variable you want to call.
The x is what string value you want.


Good luck guys
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Wed Oct 17, 2012 11:52 am

Got another update video.



I got a second controller working since the video and tested the game with some friends. Surprisingly, its pretty fun just pushing people around with the shield.


Controller:
Image

There are some bugs though:
If you move into a person's shield with your sword out, you will hurt that person (should be easy to fix by loading the shield data before the sword data)
There is a glitch where you can go through walls when another person is pushing you though with a shield (should be able to be fixed with another loading order change)
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Wed Oct 17, 2012 2:15 pm

Well, I found the character limit of the forum (60,000 characters.) Reposting the code here in 2 parts:

note: previously stated bugs appear to be fixed

Code: Select all

 //First game engine started by Joshua Little 10/08/12
//Overhead view designed to be used on LED matrix displays of any desired size
#include <avr/pgmspace.h>
#include <LiquidCrystal.h>  // include the library code

char name[][7] = {
{"Josh:"},
{"Zach:"},
{"Alex:"},
{"Corb:"},
};
byte displayY = 8;
byte displayX = 8;
byte spaceData = 0;
byte middleY = ((displayY/2)-1); //the middle of the display - 1
byte middleX = ((displayX/2)-1); //the middle of the display - 1
byte RAM = 0; //temp data used to check changes
byte lcdRefresh[] = {0, 0, 0, 0,}; //if true then LCD is refreshed

//debug

byte fps; //tha mount of frames per second
byte fpsOn = 0;
unsigned long fpsTimer = 0;
byte fpsToggle = 0;

//end debug

//LCD

byte heart[] = {0, 0, 033, 037, 016, 016, 004, 0, 0};
byte stickPerson[] = {016, 016, 004, 037, 004, 004, 012, 021};
byte skull[] = {0, 016, 037, 025, 037, 016, 0, 0};

//end LCD

//pins


LiquidCrystal lcd1(2, 7, 3, 4, 5, 6); // Rs, Enable, D4, D5, D6, D7    Controls all LCDs with 9 pins
LiquidCrystal lcd2(2, 8, 3, 4, 5, 6); // Rs, Enable, D4, D5, D6, D7
LiquidCrystal lcd3(2, 9, 3, 4, 5, 6); // Rs, Enable, D4, D5, D6, D7
LiquidCrystal lcd4(2, 9, 3, 4, 5, 6); // Rs, Enable, D4, D5, D6, D7

byte clockPin595 = 10; //595 shift register pins
byte dataPin595 = 11;
byte latchPin595 = 12;

byte muxPin[][4] = {
  {13, A1, A2},
  {A3, A4, A5},
};

byte muxInPin = A0;

//end pins

//digital buttons

byte playerButton[][9] = {   //indicates whether a player's button is pressed or not
  {0, 0, 0, 0, 0, 0, 0, 0,},         //the first 0 is the directional pad, 1 is up, 2 down, 3 left, 4 right
  {0, 0, 0, 0, 0, 0, 0, 0,},
  {0, 0, 0, 0, 0, 0, 0, 0,},
  {0, 0, 0, 0, 0, 0, 0, 0,},
};

byte swordButton[] = {0, 0, 0, 0,};
byte shieldButton[] = {0, 0, 0, 0,};
byte directionButton[][4] = {0, 0, 0, 0,};
byte startButton[] = {0, 0, 0, 0,};

//end digital buttons

//matrix stuff

byte displayData[2][9] = {0, 0,};

byte tempAnodeData[] = {0, 0, };  //used to store individual values of the anode strings
byte tempCathodeData[] = {0, 0, 0,}; //used to store individual values of the cathode strings

byte anodeString[9] =    {0b00000001, 0b00000010, 0b00000100, 0b00001000, 0b00010000, 0b00100000, 0b01000000, 0b10000000}; //scans the anode rowns
byte cathodeData[][9] = {
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,},
{0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000, 0b00000000,},
}; 

//end matrix stuff




//manual modifiers

int immunityTime[] = {1000, 1000, 1000, 1000,}; //how long a player can't get hurt after they are hit
int swordDamageDefault[] = {1, 1, 1, 1,};  //default sword damage for each player
int swordAttackTime[] = {750, 750, 750, 750,}; //the amount of time a sword is out for
int swordAttackDelay[] = {750, 750, 750, 750,}; //the amount of time until a sword can be used again
byte playerDefaultSpawnHealth[] = {5, 5, 5, 5,}; //the amount of health a player will spawn with by default
byte playerStartingHealth[] = {5, 5, 5, 5,}; //how much health a player starts with
byte playerSpawnLocation[][4] = { //where the player will spawn to upon death {x, y, map}
  {5, 6, 0,},                    // {x, y, map, sub-map}
  {9, 6, 0,}, 
  {9, 9, 0,}, 
  {5, 9, 0,}, 
 };
byte playerPos[][5] = {     // where each player is (and starts upon game start)
  {5, 6, 0,},                    // {x, y, map, sub-map}
  {9, 7, 0,}, 
  {9, 9, 0,}, 
  {5, 9, 0,}, 
 };
byte playerStartingLives[] = {3, 3, 3, 3,}; //the amount of lives each player starts with
int playerMovementDelay[] = {350, 350, 350, 350,}; //amount of time in milliseconds before a player can move again after moving

//end manual modifiers

//automated modifiers

byte swordDamageAdded[] = {0, 0, 0, 0,}; //added sword damage modifier 
byte playerAddedSpawnHealth[] = {0, 0, 0, 0,};  //the amount added to the player's default spawn health
byte playerLivesGained[] = {0, 0, 0, 0,};// the amount of lives each player has gained

//end automated modifiers

//calculated values

byte swordDamage[] = {0, 0, 0, 0,}; //calculated sword damage 
byte playerSpawnHealth[] = {0, 0, 0, 0,};  //the total amount of health a player will spawn with 
byte playerHealth[] = {0, 0, 0, 0}; //the player's health
int playerHealthAdded[] = {0, 0, 0, 0,}; //health added from having died
int playerHealthGained[] = {0, 0, 0, 0,}; //the amount of health the player has gained
byte playerLives[] = {0, 0, 0, 0}; //the current amount of lives each player has

//end calculated values

//game modifiers

byte currentPlayers[] = {1, 1, 1, 1,}; //the current players playing. if lives = 0, current players = 0                 !!!!need to automate this function
byte playerCount = 4; //the amount of players that are playing.                                                         !!!!need to automate this function
byte PvP = 1; //0 is off, 1 is on, allows players to hurt each other                                 !!!!need to automate this function
byte startAttack[] = {0, 0, 0, 0,}; //needed to determine if player can attack or not
byte directionAllow[] = {1, 1, 1, 1,}; //allows the direction of the player to change

//end game modifiers

//time values

unsigned long swordTimer[] = {0, 0, 0, 0,}; // a timer per player needed for the sword attack function 
unsigned long swordDelayTimer[] = {0, 0, 0, 0,}; //when the last sword attack was
unsigned long time;
unsigned long playerTimeSinceMovement[] = {0, 0, 0, 0,}; //the last time the player has moved is stored here
unsigned long immunityTimer[] = {0, 0, 0, 0,};

//end time values

//coordinates

byte swordPosition[][4] = { //the location of the player's swords
  {0, 0, 0,},
  {0, 0, 0,},
  {0, 0, 0,},
  {0, 0, 0,},
};

byte shieldPosition[][4] = { //the location of the players's shields
  {0, 0, 0,},
  {0, 0, 0,},
  {0, 0, 0,},
  {0, 0, 0,},
};


//end coordinates

//statistics

int playerScore[] = {0, 0, 0, 0};  //the score of each player
int playerHitsTaken[] = {0, 0, 0, 0}; //the amount of hits the player has taken     !!! not scripted
int playerDeaths[] = {0, 0, 0, 0}; //the amount of times a player has died
int playerHits[] = {0, 0, 0, 0}; //amount of times player has hit an enemy     !!! not scripted
int playerDamageDealt[] = {0, 0, 0, 0,}; //the amount of damage the player has done        !!! not scripted
int playerDamageTaken[] = {0, 0, 0, 0,}; //the amount of damage the player has recieved   !!! not scripted

//end statistics

//player modifiers

byte playerCondition[] = {0, 0, 0, 0}; //states if a player has any special status effects                          !!!!!not scripted
byte playerDirection[] = {0, 0, 0, 0}; //which way the player is facing //1 is up, 2 is down, 3 is left, 4 is right
byte playerMaxLives = 0; // the maximum amount of lives a player can have, 0 = infinite                               !!!!!not scripted
byte playerMaxHealth = 0; //the maximum amount of health a player can have, 0 = infinite                              !!!!!not scripted
int playerCurrency[] = {0, 0, 0, 0,}; //the amount of money a player has                                             !!!!!not scripted
byte playerLastMoved[] = {0, 0, 0, 0,};  //the last direction the player moved in

//end player modifiers

byte wallData = 1; //the number of a wall in the map



 const prog_uint32_t MAP0[97] PROGMEM=  //the maps in the game

  {
  0b11111111111111111111111111111111, 0b11111111111111111111111111111111,   //1
  0b10000000000000000000000000000000, 0b00000000000111111111111111111111, 
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011,
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011,
  0b10000000000000000000000000000000, 0b00000000000110000000011101110011,   //5
  0b10000000000000000000000000000000, 0b00000000000110000000011101110011, 
  0b10000000000000000000000000000000, 0b00000000000110000000010101010011, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000011, 
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011, 
  0b10000000000000000000000000000000, 0b00000000000110000000010101010011,  //10
  0b10000000000000000000000000000000, 0b00000000000110001100011101110011, 
  0b10000000000000000000000000000000, 0b00000000000110011111011101110011,
  0b10000000000000000000000000000000, 0b00000000000110011111000000000011,
  0b10000000000000000000000000000000, 0b00000000000110111110000000000111,
  0b10000000000000000000000000000000, 0b00000000000110011100000000011111,   //15
  0b10000000000000000000000000000000, 0b00000000000110000000000001111111, 
  0b10000000000000000000000000000000, 0b00000000000110000000000011111001, 
  0b10000000000000000000000000000000, 0b00000000000110000000000111100001,
  0b10000000000000000000000000000000, 0b00000000000111111111111111000001,
  0b10000000000000000000000000000000, 0b00000000000111111111111110000001,   //20
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //25
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //30
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,    //32
  
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,    //1
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //5
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,  //10
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //15
  0b11111111111111111111111111111111, 0b11111111111111111111111111111111, 
  };
  
  
  
   const prog_uint32_t MAP1[97] PROGMEM=  //the maps in the game

  {
  0b11111111100000000000000000000000, 0b00000000000000000000000000000000,   //1
  0b10000000100000000000000000000000, 0b00000000000000000000000000000000, 
  0b10000000100000000000000000000000, 0b00000000000000000000000000000000,
  0b10000000100000000000000000000000, 0b00000000000000000000000000000000,
  0b10000000100000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b10000000100000000000000000000000, 0b00000000000000000000000000000000, 
  0b10000000100000000000000000000000, 0b00000000000000000000000000000000, 
  0b11110111100000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000001100000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000011111000000000000,
  0b00000000000000000000000000000000, 0b00000000000000011111000000000000,
  0b00000000000000000000000000000000, 0b00000000000000111110000000000000,
  0b00000000000000000000000000000000, 0b00000000000000011100000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //20
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //25
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //30
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //32
  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  };
  
   const prog_uint32_t MAP2[97] PROGMEM=  //the maps in the game

  {
  0b11111111111111111111111111111111, 0b11111111111111111111111111111111,   //1
  0b10000000000000000000000000000000, 0b00000000000111111111111111111111, 
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011,
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011,
  0b10000000000000000000000000000000, 0b00000000000110000000011101110011,   //5
  0b10000000000000000000000000000000, 0b00000000000110000000011101110011, 
  0b10000000000000000000000000000000, 0b00000000000110000000010101010011, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000011, 
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011, 
  0b10000000000000000000000000000000, 0b00000000000110000000010101010011,  //10
  0b10000000000000000000000000000000, 0b00000000000110001100011101110011, 
  0b10000000000000000000000000000000, 0b00000000000110011111011101110011,
  0b10000000000000000000000000000000, 0b00000000000110011111000000000011,
  0b10000000000000000000000000000000, 0b00000000000110111110000000000111,
  0b10000000000000000000000000000000, 0b00000000000110011100000000011111,   //15
  0b10000000000000000000000000000000, 0b00000000000110000000000001111111, 
  0b10000000000000000000000000000000, 0b00000000000110000000000011111001, 
  0b10000000000000000000000000000000, 0b00000000000110000000000111100001,
  0b10000000000000000000000000000000, 0b00000000000111111111111111000001,
  0b10000000000000000000000000000000, 0b00000000000111111111111110000001,   //20
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //25
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //30
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,    //32
  
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,    //1
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //5
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,  //10
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //15
  0b11111111111111111111111111111111, 0b11111111111111111111111111111111, 
  };
  
   const prog_uint32_t MAP3[97] PROGMEM=  //the maps in the game

  {
  0b11111111111111111111111111111111, 0b11111111111111111111111111111111,   //1
  0b10000000000000000000000000000000, 0b00000000000111111111111111111111, 
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011,
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011,
  0b10000000000000000000000000000000, 0b00000000000110000000011101110011,   //5
  0b10000000000000000000000000000000, 0b00000000000110000000011101110011, 
  0b10000000000000000000000000000000, 0b00000000000110000000010101010011, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000011, 
  0b10000000000000000000000000000000, 0b00000000000110000000000000000011, 
  0b10000000000000000000000000000000, 0b00000000000110000000010101010011,  //10
  0b10000000000000000000000000000000, 0b00000000000110001100011101110011, 
  0b10000000000000000000000000000000, 0b00000000000110011111011101110011,
  0b10000000000000000000000000000000, 0b00000000000110011111000000000011,
  0b10000000000000000000000000000000, 0b00000000000110111110000000000111,
  0b10000000000000000000000000000000, 0b00000000000110011100000000011111,   //15
  0b10000000000000000000000000000000, 0b00000000000110000000000001111111, 
  0b10000000000000000000000000000000, 0b00000000000110000000000011111001, 
  0b10000000000000000000000000000000, 0b00000000000110000000000111100001,
  0b10000000000000000000000000000000, 0b00000000000111111111111111000001,
  0b10000000000000000000000000000000, 0b00000000000111111111111110000001,   //20
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //25
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //30
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,    //32
  
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,    //1
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //5
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,  //10
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001, 
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,
  0b10000000000000000000000000000000, 0b00000000000000000000000000000001,   //15
  0b11111111111111111111111111111111, 0b11111111111111111111111111111111, 
  };
  
  
 const prog_uint32_t MAPGreen0[97] PROGMEM = { //the maps in the game

  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000001100000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000011111000000000000,
  0b00000000000000000000000000000000, 0b00000000000000011111000000000000,
  0b00000000000000000000000000000000, 0b00000000000000111110000000000000,
  0b00000000000000000000000000000000, 0b00000000000000011100000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //20
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //25
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //30
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //32
  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  
  };
  
   const prog_uint32_t MAPGreen1[97] PROGMEM = { //the maps in the game

  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //20
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //25
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //30
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //32
  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  
  };
  
     const prog_uint32_t MAPGreen2[97] PROGMEM = { //the maps in the game

  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000001100000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000011111000000000000,
  0b00000000000000000000000000000000, 0b00000000000000011111000000000000,
  0b00000000000000000000000000000000, 0b00000000000000111110000000000000,
  0b00000000000000000000000000000000, 0b00000000000000011100000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //20
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //25
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //30
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //32
  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  
  };
  
     const prog_uint32_t MAPGreen3[97] PROGMEM = { //the maps in the game

  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000001100000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000011111000000000000,
  0b00000000000000000000000000000000, 0b00000000000000011111000000000000,
  0b00000000000000000000000000000000, 0b00000000000000111110000000000000,
  0b00000000000000000000000000000000, 0b00000000000000011100000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //20
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //25
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //30
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //32
  
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,    //1
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //5
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,  //10
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000,   //15
  0b00000000000000000000000000000000, 0b00000000000000000000000000000000, 
  
  };


    
Last edited by Saimaster13 on Wed Oct 17, 2012 2:16 pm, edited 1 time in total.
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Wed Oct 17, 2012 2:15 pm

Code: Select all

void setup(){

  
  pinMode(latchPin595, OUTPUT); //sets shift register pins as output
  pinMode(clockPin595, OUTPUT);
  pinMode(dataPin595, OUTPUT);
  

  
   for(int p = 0; p < 2; p++){ // for each set of 4051s
   for(int q = 0; q < 3; q++){ //for each pin going to the 4051s
     pinMode(muxPin[p][q], OUTPUT);  //sets pins as outputs and pulls low
     digitalWrite(muxPin[p][q], LOW);
   }
 }
 pinMode(muxInPin, INPUT); //sets the 4051 input pin as an input
 
lcd1.createChar(1, stickPerson);
  lcd1.createChar(2, heart);
  lcd1.createChar(3, skull);
lcd2.createChar(1, stickPerson);
  lcd2.createChar(2, heart);
  lcd2.createChar(3, skull);
lcd3.createChar(1, stickPerson);
  lcd3.createChar(2, heart);
  lcd3.createChar(3, skull);
lcd4.createChar(1, stickPerson);
  lcd4.createChar(2, heart);
  lcd4.createChar(3, skull);


  lcd1.begin(16, 2); //defines amount of LCD rows and columns
  lcd2.begin(16, 2); //defines amount of LCD rows and columns
  lcd3.begin(16, 2); //defines amount of LCD rows and columns
  lcd4.begin(16, 2); //defines amount of LCD rows and columns


}

void loop(){
  controls(); //what button controls what
  numberCalculating(); //calculates health, lives, etc.
  lcdDisplay(); //displays the LCD
  playerMovements(); //moves the player based on player controlls
  playerLocationScripts(); //scripts that run based on player's location
  playerAttacks(); //runs player attack codes
  shield();
  playerLocationUpdates(); //moves the player out of walls, etc.
  playerAttacks(); //runs player attack codes
  damage(); //calculates who or what gets hurt by how much
  debug(); //debug scrips (can remove)
  playerScripts(); //scripts such as death
  matrixDisplay(); //displays the matrix data
}

void damage(){
  swordDamageUpdate();
}

void controls(){
  controllers();
  assignButtons();
}

void matrixDisplay(){
  dataDisplayScrolling();
  matrixDisplay8x8Bi();
}

void playerAttacks(){
  sword();
}



void playerLocationUpdates(){
  shieldUpdate(); //moves players if they are in a shield or if their shield is in another person's
    wallCheck();  //checks if the player is in a wall and fixes it
}

void playerMovements(){
    playerMovement(); //moves player if movement button is pressed
}
void playerLocationScripts(){
  playerTeleport();
}

void playerScripts(){
  death();
}


void shieldUpdate(){
  for(int x = 0; x < playerCount; x++){ //for each player
    for(int y = 0; y < playerCount; y++){ //for each other player
    if((y != x)){
    if((playerPos[y][0] == shieldPosition[x][0]) && (playerPos[y][1] == shieldPosition[x][1]) && (playerPos[y][2] == shieldPosition[x][2])){ // if another player is in the same location as the shield
      playerTimeSinceMovement[x] = (time + long(playerMovementDelay));
      if(playerDirection[x] == 0){
        playerPos[y][1]--;
        playerLastMoved[y] = 0;
      }
      if(playerDirection[x] == 1){
        playerPos[y][1]++;
        playerLastMoved[y] = 1;
      }
      if(playerDirection[x] == 2){
        playerPos[y][0]++;
        playerLastMoved[y] = 2;
      }
      if(playerDirection[x] == 3){
        playerPos[y][0]--;
        playerLastMoved[y] = 3;
      }
    }}
    if((shieldPosition[y][2] !=1) && (y != x)){ //if a shield is in the same place as another shield
    if((shieldPosition[y][0] == shieldPosition[x][0]) && (shieldPosition[y][1] == shieldPosition[x][1]) && (shieldPosition[y][2] == shieldPosition[x][2])){
      playerTimeSinceMovement[x] = (time + long(playerMovementDelay));
      playerTimeSinceMovement[y] = (time + long(playerMovementDelay));
      if(playerDirection[x] == 0){
        playerPos[x][1]++;
        playerLastMoved[x] = 1;
      }
      if(playerDirection[x] == 1){
        playerPos[x][1]--;
        playerLastMoved[x] = 0;
      }
      if(playerDirection[x] == 2){
        playerPos[x][0]--;
        playerLastMoved[x] = 3;
      }
      if(playerDirection[x] == 3){
        playerPos[x][0]++;
        playerLastMoved[x] = 2;
      }
      
      if(playerDirection[y] == 0){
        playerPos[y][1]++;
        playerLastMoved[y] = 1;
      }
      if(playerDirection[y] == 1){
        playerPos[y][1]--;
        playerLastMoved[y] = 0;
      }
      if(playerDirection[y] == 2){
        playerPos[y][0]--;
        playerLastMoved[y] = 3;
      }
      if(playerDirection[y] == 3){
        playerPos[y][0]++;
        playerLastMoved[y] = 2;
      }
    }
    }
  }
  }
}


void shield(){
  for(int x = 0; x < playerCount; x++){ //for each player
    if(shieldButton[x] == 0){ //if the shield is not out
      directionAllow[x] = 1;  //allow player to change directions
      shieldPosition[x][0] = 0; //despawn the shield
      shieldPosition[x][1] = 0;
      shieldPosition[x][2] = 1;
    }
  if(shieldButton[x] == 1 && startAttack[x] == 1){ //if the shield button is pressed an the player is allowed to attack
    directionAllow[x] = 0; // prevent the player from turning
    
    if(playerDirection[x] == 0){
      shieldPosition[x][0] = playerPos[x][0]; 
      shieldPosition[x][1] = (playerPos[x][1] - 1);
      shieldPosition[x][2] = playerPos[x][2];
    }
    if(playerDirection[x] == 1){
      shieldPosition[x][0] = playerPos[x][0]; 
      shieldPosition[x][1] = (playerPos[x][1] + 1);
      shieldPosition[x][2] = playerPos[x][2];
    }
    if(playerDirection[x] == 2){
      shieldPosition[x][0] = (playerPos[x][0] + 1); 
      shieldPosition[x][1] = playerPos[x][1];
      shieldPosition[x][2] = playerPos[x][2];
    }
    if(playerDirection[x] == 3){
      shieldPosition[x][0] = (playerPos[x][0] - 1); 
      shieldPosition[x][1] = playerPos[x][1];
      shieldPosition[x][2] = playerPos[x][2];
    }

  }
  

  }
}
    
  
  
  


void playerTeleport(){
  for(int x = 0; x < playerCount; x++){ //for each player
    if(playerPos[x][2] == 0){ //if a player is on map 0
      if((playerPos[x][0] == 5) && (playerPos[x][1] == 5)){ //if player is in player house 1
        playerPos[x][0] = 59;
        playerPos[x][1] = 6;
        playerPos[x][2] = 1;
        playerLastMoved[x] = 5;
      }
    }
    if(playerPos[x][2] == 1){ // if player is on map 1
      if((playerPos[x][0] == 59) && (playerPos[x][1] == 7)){ //if player is in player house 1
        playerPos[x][0] = 5;
        playerPos[x][1] = 6;
        playerPos[x][2] = 0;
        playerLastMoved[x] = 5;
      }
    }
  }
}
        

void controllers(){
    for(int a = 0; a < playerCount; a++){ //for each extra IC
    for(int b = 0; b < 3; b++){ //BCD to decimal for first IC
      digitalWrite(muxPin[0][b], bitRead(a, b)); //writes the BCD to the decimal for the first IC
    }
    for(int c = 0; c < 8; c++){ // for each extra IC pin     
      for(int d = 0; d < 3; d++){ //BCD to decimal for second IC
        digitalWrite(muxPin[1][d], bitRead(c, d)); //writes the BCD to the decimal for the second IC
      }
      playerButton[a][c] = digitalRead(A0);
    }
  }
}
  
  
  
  

void assignButtons(){
  for(int x = 0; x < playerCount; x++){  //for each player
    for(int y = 0; y < 4; y++){ //for each direction possibility
      directionButton[x][y] = playerButton[x][y];
    }
    swordButton[x] = playerButton[x][6];
    shieldButton[x] = playerButton[x][5];
  }
}
        





//debug-------------------------------------------------------------------------------------------------------------debug

void debug(){
playerLocationCheck();
fpsChecker();

}
void playerLocationCheck(){
  for(int x = 0; x < playerCount; x++){
  if(playerButton[x][7] == 1){
lcd1.setCursor(4, 1);
lcd1.print(playerPos[x][0]);

lcd1.setCursor(7, 1);
lcd1.print(playerPos[x][1]);

lcd1.setCursor(10, 1);
lcd1.print(playerPos[x][2]);
  }
}
}

void fpsChecker(){ //checks the fps    note: fpsOn must be on to start/stop it (the button must be held)
  if(fpsOn == 0){
    fpsTimer = time;
  }
  if(playerButton[0][4] == 1){
    fpsOn=1;
  }
  if(fpsOn == 1){
    if(fpsToggle == 0){
      fpsToggle = 1;
      fps = 0;
    }
    fps++;
  }
    if((fpsTimer+1000) <= time){
      lcd1.setCursor(10,1);
      lcd1.print(fps);
      fpsOn = 0;
      fpsToggle = 0;
    }
  }





//end debug-------------------------------------------------------------------------------------------------------------end debug



//LCDs--------------------------------------------------------LCDs

void lcdRefresher(){
 if(lcdRefresh[0] == 1){
   lcd1.clear();
   lcd1.setCursor(0, 0);
   lcd1.print(name[0]);
     if(playerHealth[0] > 0){  //if player has lives then display them     //player lives
    for(int y = 0; y < (playerHealth[0]); y++){ //for each life
      lcd1.setCursor((5 + y), 0);
      lcd1.write(2);      
    }
  }
    if(playerLives[0] > 0){  //if player has lives then display them     //player lives
    for(int y = 0; y < (playerLives[0]); y++){ //for each life
      lcd1.setCursor(y, 1);
      lcd1.write(1);      
    }
  }
if(playerLives[0] == 0){
    for(int a = 0; a < 2; a++){
      for(int b = 0; b < 16; b++){
        lcd1.setCursor(b, a);
        lcd1.write(3);
      }
    }
  }
   lcdRefresh[0] = 0;
 }
 
 
 
 
 
 if(lcdRefresh[1] == 1){
   lcd2.clear();
   lcd2.setCursor(0, 0);
   lcd2.print(name[1]);
   if(playerHealth[1] > 0){   //if player has lives then display them
     for(int y = 0; y < playerHealth[1]; y++){ //for each life
       lcd2.setCursor((5 + y), 0);
       lcd2.write(2);      
    }
  } 
    if(playerLives[1] > 0){   //if player has lives then display them
    for(int y = 0; y < playerLives[1]; y++){ //for each life
      lcd2.setCursor(y, 1);
      lcd2.write(1);      
    }
  } 
  if(playerLives[1] == 0){
    for(int a = 0; a < 2; a++){
      for(int b = 0; b < 16; b++){
        lcd2.setCursor(b, a);
        lcd2.write(3);
      }
    }
  }
   lcdRefresh[1] = 0;
 }
 
 
 
 
 
 if(lcdRefresh[2] == 1){
   lcd3.clear();
   lcd3.setCursor(0, 0);
   lcd3.print(name[2]);
     if(playerHealth[2] > 0){  //if player has lives then display them
    for(int y = 0; y < playerHealth[2]; y++){ //for each life
      lcd3.setCursor((5 + y), 0);
      lcd3.write(2);      
    }
  }
    if(playerLives[2] > 0){  //if player has lives then display them
    for(int y = 0; y < playerLives[2]; y++){ //for each life
      lcd3.setCursor(y, 1);
      lcd3.write(1);      
    }
  }
  if(playerLives[2] == 0){
    for(int a = 0; a < 2; a++){
      for(int b = 0; b < 16; b++){
        lcd3.setCursor(b, a);
        lcd3.write(3);
      }
    }
  }
   lcdRefresh[2] = 0;
 }
 
 
 
 
 
 if(lcdRefresh[3] == 1){
   lcd4.clear();
   lcd4.setCursor(0, 0);
   lcd4.print(name[3]);
     if(playerHealth[3] > 0){  //if player has lives then display them
    for(int y = 0; y < playerHealth[3]; y++){ //for each life
      lcd4.setCursor((5 + y), 0);
      lcd4.write(2);      
    }
  }
    if(playerLives[3] > 0){  //if player has lives then display them
    for(int y = 0; y < playerLives[3]; y++){ //for each life
      lcd4.setCursor(y, 1);
      lcd4.write(1);      
    }
  }
if(playerLives[3] == 0){
    for(int a = 0; a < 2; a++){
      for(int b = 0; b < 16; b++){
        lcd4.setCursor(b, a);
        lcd4.write(3);
      }
    }
  }
   lcdRefresh[3] = 0;
 } 
}

void lcdDisplay(){
  lcdRefresher();
}

//end LCDs--------------------------------------------------------end LCDs



//player actions-----------------------------------------------------------------------------------------------player actions





void playerMovement(){
  for(int x = 0; x < playerCount; x++){ //for each player
   if(currentPlayers[x] == 1){ //if the player is playing

      if(directionButton[x][0] == 1 && time >= (playerTimeSinceMovement[x] + playerMovementDelay[x])){  //if up is pressed    //if player hasn't moved since the set amount of time
        playerPos[x][1]--;
        if(directionAllow[x] == 1){
          playerDirection[x] = 0;
        }
        playerLastMoved[x] = 0;
        playerTimeSinceMovement[x] = time;
        
      }
      if(directionButton[x][1] == 1 && time >= (playerTimeSinceMovement[x] + playerMovementDelay[x])){ //if down is pressed   //if player hasn't moved since the set amount of time
        playerPos[x][1]++;
        if(directionAllow[x] == 1){
          playerDirection[x] = 1;
        }
        playerLastMoved[x] = 1;
        playerTimeSinceMovement[x] = time;
      }
      if(directionButton[x][2] == 1 && time >= (playerTimeSinceMovement[x] + playerMovementDelay[x])){ //if left is pressed    //if player hasn't moved since the set amount of time
        playerPos[x][0]++;
        if(directionAllow[x] == 1){
          playerDirection[x] = 2;
        }
        playerLastMoved[x] = 2;
        playerTimeSinceMovement[x] = time;
      }
      if(directionButton[x][3] == 1 && time >= (playerTimeSinceMovement[x] + playerMovementDelay[x])){ //if right is pressed    //if player hasn't moved since the set amount of time
        playerPos[x][0]--;
        if(directionAllow[x] == 1){
          playerDirection[x] = 3;
        }
        playerLastMoved[x] = 3;
        playerTimeSinceMovement[x] = time;
      }
    }
    for(int y = 0; y < playerCount; y++){ //for each player  //makes so players cannot run into each other
          
            if(x != y ){
              if(playerPos[x][0] == playerPos[y][0] && playerPos[x][1] == playerPos[y][1] && playerPos[x][2] == playerPos[y][2]){
                if(playerLastMoved[x] == 0){
                  playerPos[x][1]++;
                }
                if(playerLastMoved[x] == 1){
                  playerPos[x][1]--;
                }
                if(playerLastMoved[x] == 2){
                  playerPos[x][0]--;
                }
                if(playerLastMoved[x] == 3){
                  playerPos[x][0]++;
              
            
            }
          }
        }
   }
   
  }
}

int MAPChooser(int x, int y, int z){ //x position, y position
  if(z  == 0){
    if(bitRead(pgm_read_dword(&MAP0[y]), x) == 1){
      return 1;
    }
    else{
      return 0;
    }
  }
  if(z  == 1){
    if(bitRead(pgm_read_dword(&MAP1[y]), x) == 1){
      return 1;
    }
    else{
      return 0;
    }
  }
  if(z  == 2){
    if(bitRead(pgm_read_dword(&MAP2[y]), x) == 1){
      return 1;
    }
    else{
      return 0;
    }
  }
  if(z  == 3){
    if(bitRead(pgm_read_dword(&MAP3[y]), x) == 1){
      return 1;
    }
    else{
      return 0;
    }
  }
  
  
}
      

void wallCheck(){ //if player moves into a wall, the play gets set back to original position
  for(int x = 0; x < playerCount; x++){      //player
    if(playerPos[x][0] <= 31){ //if player is in the first half of the map
      if(currentPlayers[x] == 1){ //map[Pmap][[Py*2], Px  //if player is in a wall
      if(MAPChooser(playerPos[x][0], ((2*playerPos[x][1])+1), (playerPos[x][2])) == 1){ 
        if(playerLastMoved[x] == 0){  //player moved back to where they were
          playerPos[x][1]++;
        }
        if(playerLastMoved[x] == 1){
          playerPos[x][1]--;
        }
        if(playerLastMoved[x] == 2){
          playerPos[x][0]--;
        }
        if(playerLastMoved[x] == 3){
          playerPos[x][0]++;
        }
        }
      }
    }
        
    if(playerPos[x][0] > 31){ //if player is in the last half of the map
      if(currentPlayers[x] == 1){ //if player is in a wall  //map[][y], y is the last half of the map y
      if(MAPChooser((playerPos[x][0]-32), (2*(playerPos[x][1])), playerPos[x][2]) == 1){
        if(playerLastMoved[x] == 0){
          playerPos[x][1]++;
        }
        if(playerLastMoved[x] == 1){
          playerPos[x][1]--;
        }
        if(playerLastMoved[x] == 2){
          playerPos[x][0]--;
        }
        if(playerLastMoved[x] == 3){
          playerPos[x][0]++;
        }
      }
      }
    }
  }
}
    
  


//end player actions-----------------------------------------------------------------------------------------------end player actions


//number calculating--------------------------------------------------------------------------------------------number calculating

void numberCalculating(){
  time = millis(); // a timer needed for timing functions
  health();
  lives();
  swordAttackDamage();
  respawnHealth();
}

void health(){                            //updates the health a character has
  for(int x = 0; x < playerCount; x++){
    RAM = playerHealth[x];
    playerHealth[x] = (playerStartingHealth[x] + playerHealthGained[x] + playerHealthAdded[x] - playerDamageTaken[x]);
    if(RAM != playerHealth[x]){
      lcdRefresh[x] = 1;
    }
  }
}

void lives(){                            //updates the lives a character has
  for(int x = 0; x < playerCount; x++){
    RAM = playerLives[x];
    playerLives[x] = (playerStartingLives[x] + playerLivesGained[x] - playerDeaths[x]);
    if(RAM != playerLives[x]){
      lcdRefresh[x] = 1;
    }
  }
}

void respawnHealth(){
  for(int x = 0; x < playerCount; x++){
    playerSpawnHealth[x] = (playerDefaultSpawnHealth[x] + playerAddedSpawnHealth[x]);
  }
}

void swordAttackDamage(){
  for(int x = 0; x < playerCount; x++){
    swordDamage[x] = (swordDamageDefault[x] + swordDamageAdded[x]);
  }
}

//end number calculating--------------------------------------------------------------------------------------------end number calculating


//scripts--------------------------------------------------------------------------------------------scripts

//end scripts--------------------------------------------------------------------------------------------end scripts


//game actions----------------------------------------------------------------------------------------game actions

void death(){                          //If a player has no health, that player respawns at spawn location, adds a death, and gets spawnhealth
  for(int x = 0; x < playerCount; x++){ //for each player
    if(playerHealth[x] <= 0 && playerLives[x] > 1){ //if player has no health but still has lives left
      for(int y = 0; y < 3; y++){                      //for each player coordinate
        playerPos[x][y] = playerSpawnLocation[x][y];
      }

      playerDirection[x] = 1;
      playerLastMoved[x] = 1;
      playerDeaths[x]++;
      playerHealthAdded[x] = (playerHealthAdded[x] + playerSpawnHealth[x]);
      playerHealth[x] = 9;
           
    }
    if(playerHealth[x] <= 0 && playerLives[x] == 1){
      playerDeaths[x]++;
      playerPos[x][0] = 9; //player spawns at map 0, x,y 0, 0
      playerPos[x][1] = 9;
      playerPos[x][2] = 0;
    }
  }
}

//game actions----------------------------------------------------------------------------------------game actions

//player attacks------------------------------------------------------------player attacks
        


void sword(){
  
  for(int x = 0; x < playerCount; x++){ //for each player
    if(swordButton[x] == 0 || (time >= swordTimer[x] + swordAttackTime[x])){
      startAttack[x] = 0;
    }
    if(startAttack[x] == 0){ //if the player is not allowed to attack then sword out timer is reset and the sword is nowhere
      swordTimer[x] = time;
      swordPosition[x][0] = 0;
      swordPosition[x][1] = 0;
      swordPosition[x][2] = 0;
    }
    
    if((time >= (swordDelayTimer[x] + swordAttackDelay[x])) && (currentPlayers[x] == 1)){  //( //if attack button is pressed and delay timer is done and player is playing
      startAttack[x] = 1;
    }
    if(startAttack[x] == 1 && swordButton[x] == 1 && (time < swordTimer[x] + swordAttackTime[x]) && (currentPlayers[x] == 1)){ //if the attack button is pressed, the player is allowed to attack, and the swordAttack time is not expired
      if(playerDirection[x] == 0){                      
        swordPosition[x][1] = (playerPos[x][1] - 1);    //sword attack directions
        swordPosition[x][0] = playerPos[x][0];
      }
      if(playerDirection[x] == 1){
        swordPosition[x][1] = (playerPos[x][1] + 1);
        swordPosition[x][0] = playerPos[x][0];
        
      }
      if(playerDirection[x] == 2){
        swordPosition[x][0] = (playerPos[x][0] + 1);
        swordPosition[x][1] = playerPos[x][1];
      }
      if(playerDirection[x] == 3){
        swordPosition[x][0] = (playerPos[x][0] - 1);
        swordPosition[x][1] = playerPos[x][1];
      }
      
      swordDelayTimer[x] = time;  //if a sword is out, then the delay timer is reset
    }
  }
}

void swordDamageUpdate(){ //used for pvp
 
  if(PvP == 1){
    for(int x = 0; x < playerCount; x++){ //attacked
      for(int y = 0; y < playerCount; y++){ //attacker
        if(playerPos[x][0] == swordPosition[y][0] && playerPos[x][1] == swordPosition[y][1] && playerPos[x][2] == swordPosition[y][2] && (time >= immunityTime[x] + immunityTimer[x])){
          playerDamageTaken[x] = (playerDamageTaken[x] + swordDamage[y]);
          playerDamageDealt[y] = (playerDamageDealt[y] + swordDamage[y]);
          immunityTimer[x] = time;
        }
      }
    }
  }
}

//end player attacks------------------------------------------------------------enplayer attacks



//matrix functions--------------------------------------------------------------------------------------matrix functions




void swordDisplayerScrolling(int x, int y, int d){ //x, y, 0 for red 1 for green           //displays the swords
      for(int z = 0; z < playerCount; z++){ //for each player
        if(swordPosition[z][0] == (x) && swordPosition[z][1] == (y) && (swordPosition[z][0] != 0 || swordPosition[z][1] != 0 || swordPosition[z][2] != 0)){
          bitClear(cathodeData[d][(y - playerPos[0][1] + middleY)], (-x + playerPos[0][0] + middleX));
        }
      }
}

void shieldDisplayerScrolling(int x, int y, int d){ //x, y, 0 for red 1 for green           //displays the shields
      for(int z = 0; z < playerCount; z++){ //for each player
        if(shieldPosition[z][0] == (x) && shieldPosition[z][1] == (y) && (shieldPosition[z][0] != 0 || shieldPosition[z][1] != 0 || shieldPosition[z][2] != 1)){
          bitClear(cathodeData[d][(y - playerPos[0][1] + middleY)], (-x + playerPos[0][0] + middleX));
        }
      }
}

void playerDisplayerScrolling(int x, int y, int d){                                   //displays the players
  for(int z = 0; z < playerCount; z++){
    if(playerPos[z][0] == (x) && playerPos[z][1] == (y) && playerLives[z] > 0){
      bitClear(cathodeData[d][(y - playerPos[0][1] + middleY)], (-x + playerPos[0][0] + middleX));
    }
  }
}

void MAPDisplayerScrolling(int x, int y, int d){
  if(x <= 31){
    if(MAPChooser(x, ((2*y)+1), playerPos[0][2]) == 1){
      bitClear(cathodeData[d][(y - playerPos[0][1] + 3)], (-x + playerPos[0][0] + 3));
    }
  }
  if(x > 31){
    if(MAPChooser((x-32), (2*y), playerPos[0][2]) == 1){
      bitClear(cathodeData[d][((y - playerPos[0][1] + 3))], (-x + playerPos[0][0] + 3));
    }
  }
}

void MAPGreenDisplayerScrolling(int x, int y, int d){
  if(x <= 31){
    if(MAPGreenDisplayChooser(x, (2*y)+1, playerPos[0][2]) == 1){
      bitClear(cathodeData[d][(y - playerPos[0][1] + 3)], (-x + playerPos[0][0] + 3));
    }
  }
  if(x > 31){
    if(MAPGreenDisplayChooser((x-32), (2*y), playerPos[0][2]) == 1){
      bitClear(cathodeData[d][((y - playerPos[0][1] + 3))], (-x + playerPos[0][0] + 3));
    }
  }
}


int MAPGreenDisplayChooser(int x, int y, int z){
  if(z == 0){
    if(bitRead(pgm_read_dword(&MAPGreen0[y]), x) == wallData){
      return 1;
    }
    else{
      return 0;
    }
  }
    if(z == 1){
    if(bitRead(pgm_read_dword(&MAPGreen1[y]), x) == wallData){
      return 1;
    }
    else{
      return 0;
    }
  }
    if(z == 2){
    if(bitRead(pgm_read_dword(&MAPGreen2[y]), x) == wallData){
      return 1;
    }
    else{
      return 0;
    }
  }
    if(z == 3){
    if(bitRead(pgm_read_dword(&MAPGreen3[y]), x) == wallData){
      return 1;
    }
    else{
      return 0;
    }
  }
}

void dataDisplayScrolling(){                                                    // determines what is displayed on the LEDs
  for(int j = 0; j < 8; j++){ //clear displays
    cathodeData[0][j] = 0b11111111;
    cathodeData[1][j] = 0b11111111;
};
  for(int y = (playerPos[0][1] - 3); y < (playerPos[0][1] + 4 ); y++){   //each line of data  //player pos y
    for(int x = (playerPos[0][0] - 3); x < (playerPos[0][0] + 4 ); x++){ //each bit of data   //player pos x
      MAPDisplayerScrolling(x, y, 0);
      playerDisplayerScrolling(x, y, 1);
      swordDisplayerScrolling(x, y, 0);
      MAPGreenDisplayerScrolling(x, y, 1);
      shieldDisplayerScrolling(x, y, 0);
      shieldDisplayerScrolling(x, y, 1);
    }
  }
}



                          

                            //8x8 LEDs, 2 colors
void matrixDisplay8x8Bi(){ //writes cathode1String[9] to display, code taken from ShiftOut on arduino website http://arduino.cc/en/Tutorial/ShiftOut
   //changes cathode 0s to 1s and 1s to 0s, also mirrors the image

  for (int j = 0; j < 8; j++) {
    //load the light sequence you want from array
    tempAnodeData[0] = anodeString[j];
    tempCathodeData[0] = cathodeData[0][j];
tempCathodeData[1] = cathodeData[1][j];
    //ground latchPin595 and hold low for as long as you are transmitting
    digitalWrite(latchPin595, 0);
    //move 'em out
  
    shiftOut(dataPin595, clockPin595, tempAnodeData[0]);
    shiftOut(dataPin595, clockPin595, tempCathodeData[0]);
    shiftOut(dataPin595, clockPin595, tempCathodeData[1]);   

    
    



   

 
    //return the latch pin high to signal chip that it 
    //no longer needs to listen for information
    digitalWrite(latchPin595, 1);

  }

}
                                      //@@@@@ do not change @@@@@
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) { //'595 matrix setup code, code taken from ShiftOut on arduino website http://arduino.cc/en/Tutorial/ShiftOut
  int i=0;   // This shifts 8 bits out MSB first, on the rising edge of the clock, clock idles low
  int pinState;                //internal function setup
  pinMode(myClockPin, OUTPUT);
  pinMode(myDataPin, OUTPUT);
  digitalWrite(myDataPin, 0);   //clear everything out just in case to prepare shift register for bit shifting
  digitalWrite(myClockPin, 0);
  for (i=7; i>=0; i--)  {   //for each bit in the byte myDataOut� NOTICE THAT WE ARE COUNTING DOWN in our for loop This means that %00000001 or "1" will go through such that it will be pin Q0 that lights. 
    digitalWrite(myClockPin, 0);
    if ( myDataOut & (1<<i) ) {      //if the value passed to myDataOut and a bitmask result true then... so if we are at i=6 and our value is %11010100 it would the code compares it to %01000000 and proceeds to set pinState to 1.
      pinState= 1;
    }
    else {	
      pinState= 0;
    }
    digitalWrite(myDataPin, pinState);    //Sets the pin to HIGH or LOW depending on pinState
    digitalWrite(myClockPin, 1);    //register shifts bits on upstroke of clock pin  
    digitalWrite(myDataPin, 0);  //zero the data pin after shift to prevent bleed through
  }
  digitalWrite(myClockPin, 0);  //stop shifting
}


//end matrix functions--------------------------------------------------------------------------------------end matrix functions
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Wed Oct 17, 2012 9:21 pm

I am thoroughly impressed!

Love the new video as well. I can't get over how much you are just like me! going through your code there are so many similarities as to how I would go about making a game like this. Just let me know how you would like the level converter for the game to operate and it will be simple to get it going for you. I.E. if you want it to be able to output 32 bit words etc... Just send me the details in a PM and i'll work on it over the next few days when I get some time.

I was especially impressed with how you can go into a house and it then changes to show you in the house. It really goes to show that you don't need great graphics to have great gameplay - you just need to have some little pixels and a good story line :)

How much does it compile to now? do you think you might need external memory - maybe a serial eeprom?

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Wed Oct 17, 2012 9:57 pm

How much does it compile to now? do you think you might need external memory - maybe a serial eeprom?
It now compiles down to 14kb with 4 maps. I did some math, and believe that the maximum amount of 64x48 pixel maps that can be programmed is 25, then the Arduino's data will be full. I definitively don't need serial eeprom right now, but I might later if I make the game really big.

What I do need is faster refresh rates for the matrices I plan on upgrading to. I believe that with how big I want to go, the Arduino's fps (I have an in code function that calculates it) will be too low, so, the only thing I can think of is getting more Arduinos into the picture. What I have no idea about is whether I should send data from the main Arduino to matrix driver Arduinos, or add a data manager Arduino between them. (If there was only the main Arduino and the display Arduinos, then the main Arduino would send the cathode data to the appropriate display Arduinos which would then scan the rows and display that data. If a data manager was present, the main Arduino would send the player's positions and whether the player's swords or shields were out or not. The data manager would then calculate the cathode data and send it to the display drivers. The problem with this approach though is the eventual expansion of npcs and enemies: it would be hard to fit them in.) Another problem of mine is that I have no idea how to send data between Arduinos at an efficient rate (my first idea was to use shift registers connected to 8-3 decoders connected to the display Arduinos to tell them what to display. Is this an efficient way, is there a better way?)

So, simple answers:
I do not currently need more memory
How should I communicate to other Arduinos efficiently? I am looking for the fastest way with the fewest delay()s. Also it should be noted that I only have ~3-4 pins available on the main Arduino (but 20 on the others.)

I'm glad you like the game by the way!
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Thu Oct 18, 2012 6:00 am

I just realized: I do not know how to adequately power LED matrices.

What I need for right now is to know how to power two or four 2x2 matrix of 8x8 matrices.
Where each x is a 8x8 matrix, what I am making will look sort of like this:

xx xx xx xx
xx xx xx xx

Either all of them will be driven together, or the first two 2x2 matrix of matrices will be driven together, and the other matrices will be driven separately.

So it is effectively going to be either a 2 row and 4 column matrix of matrices, or a 2 row 8 column matrix of matrices, totaling to either a 16x32 or 16x64 pixel matrix.


My hardware:
Arduino
74HC595 shift registers
eight 8x8 matrices (I will eventually get 8 more to double the matrix count.I have yet to decide whether they will be powered by the same Arduino or not.)


Also, it should be noted that I have 74HC373 and '374s, but do not know how to use either. Should I use one of these instead of the '595s?


What I have on hand for current (sinking or sourcing, I'm not sure which.):
resistors
10x ULN2803APG transistor arrays
2n2222a Transistors




I am willing to get whatever I need to properly power the matrices. However, I would prefer, if it would work just as well, to use the transistor arrays I already have to power the matrices.



Links:

Link to download ULN datasheet

link to matrix datasheet
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Thu Oct 18, 2012 9:34 am

I just typed up the intro. It now compiles down to 20kb. So what was that about extra memory and serial eeprom?
Joshua

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Thu Oct 18, 2012 12:48 pm

Another video showing what scripts I put in so far. Since the video I put in a start menu and introduction text explaining why you are there and guiding you to what happens next (not that there is currently something that happens next.)

Another controller is under construction and when I know how to properly sink and source power to a matrix I'll make two bigger displays, followed by a third and fourth eventually.


Scripts video:
Joshua

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Fri Oct 19, 2012 7:00 am

First of all - the video update is so cool! The LCD screen letting you know what is what really adds depth to the game - I guess it's sort of like reading a book. There are no pictures in a novel but you draw the pictures up in your head. This is shaping up to be an extremely fun game to play. Actually, I look forward to playing it once complete!

Now let me do a write up of your other questions...

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Fri Oct 19, 2012 8:49 am

Saimaster13 wrote:I just typed up the intro. It now compiles down to 20kb. So what was that about extra memory and serial eeprom?
I would use a serial eeprom (or perhaps SPI memory) to hold onto all of your constants data (like game screens and LCD text etc...)

That way all of your program memory will basically be used for just the game code. The code will then call data from the external memory when it needs to (just as it it was calling it straight from program memory.)

Have a read through this for more info:
http://www.arduino.cc/playground/Main/SpiRAM

And this one:
http://seemanta.net/myblog/?p=261

User avatar
brad
Site Admin
Site Admin
Posts: 2578
Joined: Fri Mar 26, 2010 10:30 pm
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by brad » Fri Oct 19, 2012 10:20 am

Saimaster13 wrote:I just realized: I do not know how to adequately power LED matrices.

What I need for right now is to know how to power two or four 2x2 matrix of 8x8 matrices.
Where each x is a 8x8 matrix, what I am making will look sort of like this:

xx xx xx xx
xx xx xx xx

Either all of them will be driven together, or the first two 2x2 matrix of matrices will be driven together, and the other matrices will be driven separately.

So it is effectively going to be either a 2 row and 4 column matrix of matrices, or a 2 row 8 column matrix of matrices, totaling to either a 16x32 or 16x64 pixel matrix.


My hardware:
Arduino
74HC595 shift registers
eight 8x8 matrices (I will eventually get 8 more to double the matrix count.I have yet to decide whether they will be powered by the same Arduino or not.)


Also, it should be noted that I have 74HC373 and '374s, but do not know how to use either. Should I use one of these instead of the '595s?


What I have on hand for current (sinking or sourcing, I'm not sure which.):
resistors
10x ULN2803APG transistor arrays
2n2222a Transistors




I am willing to get whatever I need to properly power the matrices. However, I would prefer, if it would work just as well, to use the transistor arrays I already have to power the matrices.



Links:

Link to download ULN datasheet

link to matrix datasheet
The main problem here is the amount of rows being activated at once is not enough. Let's just say that you are sending out 1 bit every 1uS. If you have a bi-color 8x8 matrix then it will take 8*8*2 = 128uS to send out your red and green colors to the display. You then need to allow a delay of perhaps 1mS for each time you activate a row of LED's - so you have and extra 8mS delay for an 8 column display. If you then go worst case scenario and have a 64x16 pixel (bi-color) display then you are looking at needing 16 of these 8x8 matrix displays. so:

128uS to send data out per display + 8mS to actually be able to show the image multiplied by 16 displays = approx 130mS all up. That's just to scan through once. But you need to be updating these displays at a rate of around 24 times a second (to prevent flicker)

But if we run the math 1/0.13 = 7.69. That means that you will only be able to show 7.69 frames per second which means a whole lot of flicker!

So what if you where to use 74373's? Well, this would help, but only slightly - the only difference here is that you are sending a whole byte out to the matrix per clock pulse instead of only sending a single bit per clock pulse. this means that you will wipe out 7uS per row per display So:

7uS * 8 columns * two colors * 16 displays = 1.79mS this means you will have drawn one image 1.79mS quicker than if you sent the data out serially. It did take 130mS previously so now it will take 130mS - 1.79mS = 128.21mS which is still not quick enough!

Notice how we don't really have a problem with how fast we can send out the data? the main problem is with holding the data on those LED's for long enough for us to see them properly. What you need to do is send multiple rows of data out at a time, then turn on multiple rows of LED's at a time, before sending out the new data.

hopefully this picture should help!
16x32Display.PNG
16x32Display.PNG (53.76 KiB) Viewed 182448 times

User avatar
Saimaster13
I practically live here!
I practically live here!
Posts: 176
Joined: Mon Aug 13, 2012 4:23 am
Location: Sarasota, Florida
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Re: RPG game + LED pixel game system hardware

Post by Saimaster13 » Fri Oct 19, 2012 12:52 pm

I don't understand how I would split an 8x8 matrix into 4 rows. Wouldn't the cathode data be doubled on a single matrix if two rows were active at the same time? Also, to provide the extra mA needed to power larger matrices, won't I need to add some transistors to source and sink power?

Also, you plan on building this project once completed?
Joshua

Post Reply
[phpBB Debug] PHP Warning: in file [ROOT]/vendor/twig/twig/lib/Twig/Extension/Core.php on line 1266: count(): Parameter must be an array or an object that implements Countable

Who is online

Users browsing this forum: No registered users and 3 guests