[Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Developed or developing a new product in PureBasic? Tell the world about it.
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Mijikai »

threedslider wrote: Sun Dec 03, 2023 9:53 am Hello Mijikai,

It is awesome your lib ! :shock: Thank you for sharing :mrgreen:

Can you provide an example of 2D game as 2D platform, please ? I want to make a 2D game platform ^^

Good job and keep it up bro !
Thank you threedslider,
i made a very simple example the movement and collision routines are just a quick hack!
But if improved on this can be a good starting point :)

Image

Code: Select all


EnableExplicit

XIncludeFile "rpix.pbi"

Procedure.i Main()
  Protected *rpix.RPIX,*Map.RPIX_SURFACE,*guy.RPIX_SURFACE
  Protected.i x,y,j,u,oy,ox
  *rpix = rpixWindow(#RPIX_WINDOW_NORMAL,640,512,320,256,#True)
  If *rpix
    *map = *rpix\BufferSurface();<- create a map sprite from the backbuffer (same size)
    *rpix\DrawBox(*map,0,250,320,256,100,#True);<- draw map elements
    *rpix\DrawBox(*map,0,200,40,2,100,#True)
    *rpix\DrawBox(*map,100,220,40,2,100,#True)
    *rpix\DrawBox(*map,150,200,40,2,100,#True)
    *rpix\DrawBox(*map,220,200,40,2,100,#True)
    *guy = *rpix\SurfaceCreate(8,16);<- create a player sprite
    *guy\BufferFill(255);<- make it white (using the grayscale palette entry 255)
    *guy\BufferSet(2,4,0);<- draw some eyes on the player sprite
    *guy\BufferSet(6,4,0)
    x = 100;<- set the players starting position
    y = x
    Repeat
      *rpix\InputUpdate() ;<- handle user input
      ox = x;<- safe old player position
      oy = y
      x + *rpix\InputKeyDown(#VK_RIGHT);<- handle player movement 
      x - *rpix\InputKeyDown(#VK_LEFT) 
      If *rpix\InputKeyToggle(#VK_UP) And j = #False;<- handle player jump
        u = y;<- from where is the player jumping
        j = #True ;<- set jumping to #True
      EndIf
      If j;<- when jumping do all this...
        y - 2
        If y = u - 30
          j = #False
        EndIf
      Else
        y + 2
      EndIf
      *map\BufferWrite(0);<- start rendereing (first the map is written/copied to the backbuffer)
      If *guy\Test(0,x,y,0,100,#True) And oy <> y And y > oy;<- do some pixel collision detection for the player
        y = oy;<- reset the players y position if there is a hit
      EndIf 
      *guy\Draw(0,x,y,#True);<- draw the player
      *rpix\DrawText(0,160,16,"USE DIRECTION KEYS TO MOVE AND JUMP!",140,#True);<- draw some text
      *rpix\BufferDrawEvent();<- render the backbuffer to the screen
    Until *rpix\WindowExit()
    *rpix\WindowClose()
  EndIf
  ProcedureReturn #Null
EndProcedure

End Main()
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Mijikai »

Update v.1.02:
- Fixed a memory bug.

Download:
https://www.dropbox.com/scl/fi/kea1bb3v ... 4q9ra&dl=0
threedslider
Enthusiast
Enthusiast
Posts: 377
Joined: Sat Feb 12, 2022 7:15 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by threedslider »

Nice ! Thank you Mijikai !!
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Mijikai »

Some shenanigans for a platformer with slopes :)
Image
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by mrbungle »

Very cool demos!
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by mrbungle »

This would be amazing for the Mac too!
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Mijikai »

Thanks @mrbungle, a Mac version is not planned yet.
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Mijikai »

Example Simple Console:
Image

Code:

Code: Select all

EnableExplicit

;Simple Console Template
;Author: Mijikai

XIncludeFile "rpix.pbi"

Structure CONSOLE_STRUCT
  *rpix.RPIX
  *surface.RPIX_SURFACE
  *header.RPIX_SURFACE
  *footer.RPIX_SURFACE
  *cursor.RPIX_SURFACE
  *lead.RPIX_SURFACE
  width.i
  height.i
  colums.i
  rows.i
  text.s
  char.s
  code.i
  exit.i
EndStructure

Global console.CONSOLE_STRUCT

Procedure.i ConsoleInit(Title.s)
  With console
    \rpix\PaletteSet(1,$FFCE20);<- set console colors
    \rpix\PaletteSet(2,$FF76EB)
    \rpix\PaletteSet(3,$477D99)
    \rpix\PaletteSet(4,$FFFFFF)
    \rpix\PaletteSet(5,$376D89)
    \rpix\PaletteSet(6,$DDDDDD)
    \rpix\OutputSize(@\width,@\height)
    \surface = \rpix\BufferSurface()
    \header = \rpix\SurfaceCreate(\width,8)
    \footer = \header\Duplicate()
    \cursor = \rpix\SurfaceCreate(8,8)
    \lead = \cursor\Duplicate()
    If \surface And \header And \footer And \cursor And \lead
      \colums = \width >> 3
      \rows = (\width >> 3) - 1
      \surface\BufferFill(5);<- create console graphics
      \header\BufferFill(3)
      \rpix\DrawText(\header,\width >> 1,0,Title,4,#True)
      \rpix\DrawText(\header,(\width >> 1) + 1,0,Title,4,#True)
      \footer\BufferFill(3)
      \cursor\BufferFill(3)
      \lead\BufferFill(5)
      \rpix\DrawText(\lead,1,0,">",1)
      \rpix\DrawText(\lead,3,0,">",2)
      \rpix\DrawBox(\lead,0,0,8,8,5)
      \rpix\DrawBox(\cursor,0,0,3,8,1,#True)
      \rpix\DrawBox(\cursor,4,0,3,8,2,#True)
      ProcedureReturn #True
    EndIf
    ProcedureReturn #False
  EndWith
EndProcedure

Procedure.i ConsoleSpace(Rows.i);<- modify this to make space for multiple lines of text (ex. a list would be good)
  Protected index.i
  With console
    Rows - 1
    If \text
      \lead\Draw(\surface,0,\height - 8)
      \rpix\DrawText(\surface,8,\height - 8,\text,6);4
    EndIf
    \rpix\DrawBox(\surface,0,0,\width,8,5,#True)
    For index = 0 To Rows
      \surface\BufferScroll(-8,#True);<- scroll the surface/sprite to make space for new text
    Next
    \text = ""
    ProcedureReturn #Null
  EndWith
EndProcedure
    
Procedure.i ConsoleInput();<- basic command parser
  With console
    Select \text
      Case "help"
        \text = "Command: '" + \text + "'"
        ConsoleSpace(1)
        \text = "AVAILABLE COMMANDS: help; hello; exit"
      Case "hello"
        \text = "Command: '" + \text + "'"
        ConsoleSpace(1)
        \text = "Hello World!"
      Case "exit"
        \exit = #True
        \text = "Command: '" + \text + "'"
        ConsoleSpace(1)
        \text = "EXIT PROGRAM!"
    EndSelect
    ConsoleSpace(1)
    ProcedureReturn #Null
  EndWith
EndProcedure             
            
Procedure.i ConsoleUpdate()
  With console
    \rpix\InputUpdate()
    If \rpix\InputKeyChar(@\code) Or \text = "";<- handles keys & input
      \char = Chr(\code)
      \code = \rpix\InputKeyMapToCode(\char)
      If \code = #VK_BACK
        \text = Left(\text,Len(\text) - 1)
      ElseIf \code = #VK_RETURN
        ConsoleInput() 
      Else
        If Len(\text) < 39
          \text + \char
        EndIf
      EndIf
    EndIf 
    \surface\BufferWrite(#Null);<- draw everything
    \header\Draw(#Null,0,0)
    \footer\Draw(#Null,0,\height - 8)
    If \text
      \cursor\Draw(#Null,Len(\text) << 3,\height - 8)
    Else
      \cursor\Draw(#Null,\width - 7,\height - 8)
    EndIf
    \rpix\DrawText(#Null,0,\height - 8,\text,4)
    \rpix\BufferDrawEvent()
    \rpix\InputFlush()
    ProcedureReturn #Null
  EndWith
EndProcedure

Procedure.i Main()
  With console
    \rpix = rpixWindow(#RPIX_WINDOW_NORMAL,640,400,320,200,#True)
    If \rpix
      If ConsoleInit("CONSOLE")
        Repeat
          ConsoleUpdate()
          If \exit;<- delay the exit by command
            \exit + 1
          EndIf
        Until \rpix\WindowExit() Or \rpix\InputKeyToggle(#VK_ESCAPE) Or \exit > 100
      EndIf
      \rpix\WindowClose()
    EndIf
    ProcedureReturn #Null
  EndWith
EndProcedure

End Main()

threedslider
Enthusiast
Enthusiast
Posts: 377
Joined: Sat Feb 12, 2022 7:15 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by threedslider »

Nice work to your last update that I have seen today :oops: !

Any update on your side Mijikai :)

Keep it up bro ! Thanks
User avatar
Mijikai
Addict
Addict
Posts: 1517
Joined: Sun Sep 11, 2016 2:17 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by Mijikai »

About the state of this project:

I recently switched to Linux :mrgreen:
But don't worry, this project is not dead, I'm just busy rewriting rpix - it will be platform independent.
This will take some time.
Preview (added support for rotation, scaling & stretching) 8) :
Image
User avatar
jacdelad
Addict
Addict
Posts: 1991
Joined: Wed Feb 03, 2021 12:46 pm
Location: Riesa

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by jacdelad »

This is one of the cool projects with a lot of work in it and I can't find a usecase yet... :cry:
Good morning, that's a nice tnetennba!

PureBasic 6.21/Windows 11 x64/Ryzen 7900X/32GB RAM/3TB SSD
Synology DS1821+/DX517, 130.9TB+50.8TB+2TB SSD
User avatar
idle
Always Here
Always Here
Posts: 5834
Joined: Fri Sep 21, 2007 5:52 am
Location: New Zealand

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by idle »

Mijikai wrote: Sun Oct 13, 2024 7:02 pm About the state of this project:

I recently switched to Linux :mrgreen:
But don't worry, this project is not dead, I'm just busy rewriting rpix - it will be platform independent.
This will take some time.
Preview (added support for rotation, scaling & stretching) 8) :
Image
Will be good to have it cross platform :D
mrbungle
Enthusiast
Enthusiast
Posts: 143
Joined: Wed Dec 30, 2020 3:18 am

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by mrbungle »

This is great. I look forward to the cross-platform version!
PrincieD
Addict
Addict
Posts: 858
Joined: Wed Aug 10, 2005 2:08 pm
Location: Yorkshire, England
Contact:

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by PrincieD »

Very cool! 8)
ProGUI - Professional Graphical User Interface Library - http://www.progui.co.uk
threedslider
Enthusiast
Enthusiast
Posts: 377
Joined: Sat Feb 12, 2022 7:15 pm

Re: [Windows x64] RetroPixel a 2D 8-Bit (256 Color) GFX Library - DEV

Post by threedslider »

Well come back ! It is nice to see your progress and keep it up please :mrgreen:
Post Reply