Set pixel in the world, not on the screen.

Post here to discuss all things DigiPixel related.

Moderators: Chuckt, Garth, bitfogav

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[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

Set pixel in the world, not on the screen.

Post by ZephaniahNoah » Fri Aug 28, 2015 12:46 pm

I'm having a hard time creating npc's and things that move in the world without inhibiting the players movement so that I can use the setPixel function. But what would make this a whole lot easier, and more interactive, would be a set pixel world function. For example: When you set a pixel in the world it would put it into the Program memory array and saveGraphics() would then display it. Maybe this is already possible without implementing a new function. Or perhaps there is a better way of doing it. What are your thoughts?
Last edited by ZephaniahNoah on Tue Sep 22, 2015 5:37 pm, edited 1 time in total.
DigiPixel is AWESOME! Image

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: Set World pixel function.

Post by brad » Mon Aug 31, 2015 9:54 am

Sorry for the late reply.

Could you give a little example of some code that you are working through?

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[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: Set World pixel function.

Post by ZephaniahNoah » Tue Sep 01, 2015 6:03 am

I made two pictures. One with the pixel I wanted, And one without it. When I wanted the pixel I would activate setMyPixel()

Code: Select all

void setMyPixel(){
    long MyDataRed[700]PROGMEM={X}
    long MyDataGreen[700]PROGMEM={X}
    long MyDataBlue[700]PROGMEM={X}
}
X = My picture with the pixel I want to add. I got no errors but it didn't work. I think I need to add the pixel to the original Program memory arrays, but I get all sorts of errors when I try that. Perhaps you now how?
Last edited by ZephaniahNoah on Fri Sep 04, 2015 12:55 pm, edited 1 time in total.
DigiPixel is AWESOME! Image

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: Set World pixel function.

Post by brad » Wed Sep 02, 2015 11:30 am

I think I understand what you are getting at now.

Correct me if i'm wrong but are you trying to get a certain pixel set within an array which for example, would hold all data throughout a level? For instance, if you have a level that is 700 pixels wide and 8 pixels high, and your player is required to jump on a certain platform lets say. Once they jump on the platform, a key appears some where else in the level. So therefore you would want to set a certain pixel somewhere within the 700x8 pixel array so that when the player walks over to that section, the key is now displayed. Is that the sort of thing you're trying to do?

If so, unfortunately you can't modify the contents of PROGMEM during runtime, you can only copy data to it at burn time, and then all you can do is read it at run time. The reason for using PROGMEM is so that we don't use up all of the SRAM.

Here's a good page with some useful info on PROGMEM:
http://arduino.stackexchange.com/questi ... ng-progmem

Moreover, an atmega328 microcontroller has 32KB of program memory but only 2KB of SRAM. if each level is 700 pixels wide and you have red, green, blue and barrier components to them, you are looking at 700bytes x 4 = 2,800 Bytes or 2.8KB - If you made your levels smaller (say 300 pixels wide) and then pre-loaded SRAM with your level data from PROGMEM, you could then change whatever you wanted at run time. I.E. you could easily set or clear whatever pixel you wanted.

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[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: Set World pixel function.

Post by ZephaniahNoah » Fri Sep 04, 2015 12:54 pm

Yes. You are correct. That's what I was trying to do. Man that sucks PROGMEM is read only. I kinda guessed that was the case because it wasn't letting me change it. Sorry if I was being too vague about the setPixelWorld thingy I was talking about. Let me go into more detail... What if you could create an overlay so that when you put a pixel in that overlay it displays as a pixel overlaying the world. So that instead of displaying it attached to the screen it displays it as if it were part of the world. I think this could work by checking the player's position and moving the pixel around the screen as the player moves making it look as if it's part of the world/PROGMEM. For example: I want a yellow pixel here in the world. Instead of using these top two maps and switching the player between the two I can just add the overlay (on the bottom) to the picture so that when the player moves over they'll see it.
Image
As I said I'm pretty sure it's possible and I'm working on it and it involves quite a bit of code and implementing it as another function in the DigiPixel libraries would make it a lot easier when setting multiple pixels. Sorry if I'm not using the right names for things or not explaining myself very well. I'll try to send you the code if I ever figure it out.
DigiPixel is AWESOME! Image

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: Set World pixel function.

Post by brad » Sat Sep 05, 2015 9:50 am

It would certainly be easier to do this if all the level data was stored in SRAM because you can read from and write to it. So you might have an 'enemy' pixel located at the X, Y co-ordinates of 478, 4. You would just need to set pixel 478, 4 whichever color you wanted within the level data stored in SRAM, then when you're player eventually got to that section of the level, you would see that 'enemy' pixel.

Here is a youtube video of the super pixel bros game that I programmed using Swordfish Basic on a PIC microcontroller, it has 'enemy' pixels that appear on the screen when the player gets to a point that he can actually see them:


Here is some code (in Basic) that shows sending the data to the graphics arrays which would then be sent out to the LED's:

Code: Select all

Sub DrawGraphics()
    For x = StartColumn To (StartColumn + 7)
        GraphicDataOutGreen = 0
        GraphicDataOutRed = 0
        GraphicDataOutBlue = 0
        GraphicDataOutGreen = GraphicDataOutGreen Or LevelBufferGreen(x) 
        GraphicDataOutRed = GraphicDataOutRed Or LevelBufferRed(x)
        GraphicDataOutBlue = GraphicDataOutBlue Or LevelBufferBlue(x)
        
        ' this code will draw the bad guy on the screen   (red and blue = magenta badguy!)
        If BadGuyX = x And BadGuyY < 8 Then       ' only draw him if he is in the screen
           GraphicDataOutBlue.bits(BadGuyY) = 1
           GraphicDataOutRed.bits(BadGuyY) = 1
        EndIf
        
        ' this draws the player on the screen
        If PlayerX = (7 - (x - StartColumn)) Then
           If PlayerY <= 7 And PlayerY >= 0 Then   'ensure that we only inlude this info in our data IF THE PLAYER IS ON THE SCREEN VERTICALLY!
              GraphicDataOutRed.bits(PlayerY) = 1
           EndIf
        EndIf
    Next  
End Sub
I hope that helps, it's not arduino code but it's quite similar in its syntax

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[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: Set World pixel function.

Post by ZephaniahNoah » Mon Sep 07, 2015 3:57 pm

Alright, thanks. I'll use the SRAM to store my map if I can't get my method to work. I would just go for the SRAM method right away but my map is 700 pixels wide and I don't want to remake it. Thank you for the help!

P.S. Can Swordfish Basic write code to an Arduino, or would I need a pic?
DigiPixel is AWESOME! Image

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: Set World pixel function.

Post by brad » Wed Sep 09, 2015 10:07 pm

That is a big map! When I made Super Pixel Bros, each game map was just 120 pixels wide :)

Unfortunately, Swordfish Basic is just for the 18F series of PIC microcontrollers. I very much prefer coding in it rather than any other programming language that I have used but unfortunately it just does not have a big fan base anymore. There used to be a wonderful thriving community for Swordfish Basic and then it seemed to all die off...

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[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: Set World pixel function.

Post by ZephaniahNoah » Thu Sep 10, 2015 12:00 pm

Shrinking community? Awe... That's disappointing :( Anyways I got my method to work! I can get hurt by my bad guy if touched by the side, and I can kill it by jumping on top of it. And for the whole reason I'm doing this, can make the bad guy move around in the world too! I'm just having trouble making him move back and fourth atm.
DigiPixel is AWESOME! Image

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: Set World pixel function.

Post by brad » Fri Sep 11, 2015 8:47 pm

Any chance you can post your code so I can try it out?

User avatar
bitfogav
Moderator
Moderator
Posts: 915
Joined: Sun Mar 28, 2010 9:03 pm
Location: United Kingdom
Contact:

Re: Set World pixel function.

Post by bitfogav » Sun Sep 13, 2015 11:07 pm

brad wrote:Unfortunately, Swordfish Basic is just for the 18F series of PIC microcontrollers. I very much prefer coding in it rather than any other programming language that I have used but unfortunately it just does not have a big fan base anymore. There used to be a wonderful thriving community for Swordfish Basic and then it seemed to all die off...
I think a lot of electronic/programming communities have died a little recently which is kind of sad :cry:
The few web sites I often check on regularly often don't change or get updated anymore.. But anyway I use my Digipixel with Swordfish Basic.. :D
If you don't know what Voltage your country is using, you shouldn't be doing electronics ;-)

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: Set World pixel function.

Post by brad » Mon Sep 14, 2015 9:28 pm

bitfogav wrote:
brad wrote:Unfortunately, Swordfish Basic is just for the 18F series of PIC microcontrollers. I very much prefer coding in it rather than any other programming language that I have used but unfortunately it just does not have a big fan base anymore. There used to be a wonderful thriving community for Swordfish Basic and then it seemed to all die off...
I think a lot of electronic/programming communities have died a little recently which is kind of sad :cry:
The few web sites I often check on regularly often don't change or get updated anymore.. But anyway I use my Digipixel with Swordfish Basic.. :D
It is a bit sad bitfogav :) but always good to catch up with old friends now and again!

Be sure to let us know of any projects that you may have going :)

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[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: Set World pixel function.

Post by ZephaniahNoah » Fri Sep 18, 2015 6:42 am

brad wrote:Any chance you can post your code so I can try it out?
Yea! Will do! Since I figured this out I've been filled with all kinds new ideas. Not quite finished yet though.
DigiPixel is AWESOME! Image

User avatar
ZephaniahNoah
semi-newbie
semi-newbie
Posts: 24
Joined: Wed Dec 31, 2014 7:17 am
Location: Milky Way, Earth
[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: Set World pixel function.

Post by ZephaniahNoah » Tue Sep 22, 2015 5:31 pm

brad wrote:Any chance you can post your code so I can try it out?
Well I guess I have to give you the code now. After creating a button that opens a door I had begun adding more things. And after the project reached over 17,000 bytes the digiPxel.getPixel function completely stopped working. To be sure that this was the problem I deleted some code so that it would only be 16,726 bytes and the digiPxel.getPixel function started working again. Do you know of any way to fix this? I don't want to have to make my world smaller.
Image
In the red hut you get on the purple rope and press down to slide down. It does this by checking for purple barrier at (4,3). But it's not working. I made a hole leading to the lava where it checks (4,3) using getPixel to see if it is equal to red barrier so it will kill the player. But that doesn't work either, because it uses the digiPxel.getPixel function. IDK what's wrong. :(
EDIT: Also I got rid of the bad guy. But he, and others, will probably be back later. And remember, I use Arduino 1.0.6...
Attachments
MyDigiPixelGame.zip
The File. (I use Arduino 1.0.6, but feel free to make the necessary code tweaks to make it compatible.)
(7.48 KiB) Downloaded 788 times
DigiPixel is AWESOME! Image

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: Set pixel in the world, not on the screen.

Post by brad » Fri Sep 25, 2015 7:11 am

Have just downloaded it, will see about giving it a test run as soon as I find some time however I need to fix my Arduino first because I needed to borrow some of the female headers on it :)

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 1 guest