What about them graphical pictures?

So text is cool. But what about the pixels? I was thinking about what to do next. I had variables and text on screen. So what would the next step be?

I want to make a game for the Brick and if I made a game for it then it should make use of the fact that it is a Lego robot. The game should use of the sensors and motors somehow.  I still haven’t decided what game to make but I love adventure games and I feel like I am on an adventure of sorts trying to find my way through the EV3 VM, so I figured I wanted to do a tile based adventure game, Zelda style.

So I need to draw graphics to the screen!

The opcodes seems to provide a few options. I can for example draw an image or set individual pixels. Setting individual pixels wasn’t super interesting since it would probably be too slow to use in a game anyways, so I looked at drawing an image. The function accepted 4 parameters, where one was a string with what seemed like a name. I looked into the native implementation of the function and saw that what I thought was a file name was only used as a lookup into a dictionary of loaded images so I was confused. How would images end up in that dictionary?

I looked at other image functions to see if any of them would load pictures and I looked at the file functions, but the function that load images was nowhere to be found. After looking around for a while I started suspecting that images would be loaded automatically so after a while I just copied the image file to the same folder as my RBF and started it, and lo and behold, the image was drawn on screen at the coordinate I asked for. It was as simple as that. I don’t know about the performance for this, if it is faster to load the image into memory first if I intend to draw tons of files.

vmthread  MAIN
  DATA8 Run
  DATA8 DrawX
  DATA8 Flag
  DATA16 DrawX16

  MOVE8_8(1, Run)
  MOVE8_8(0, DrawX)

  UI_DRAW( FILLWINDOW,0x00,0,0 )                 // Clear screen
  MOVE8_16( DrawX, DrawX16 )
  UI_DRAW( BMPFILE,FG_COLOR,DrawX16,50,'Bomb' )  // Draw bomb image
  UI_DRAW( UPDATE )                              // Show the stuff

  //ADD8(1, DrawX, DrawX)                        // DrawX++

  // Check for reset
  CP_GTEQ8(DrawX, 20, Flag)                      // IF DrawX >= 20 THEN Flag=1
  JR_FALSE(Flag, NoResetDrawX)                   // IF Flag==1 THEN JP NoResetDrawX

  // Do reset
  MOVE8_8( 0, DrawX )

  // Check for key to exit
  UI_BUTTON( SHORTPRESS, BACK_BUTTON, Flag )     // IF backbutton pressed THEN Flag=1
  JR_FALSE( Flag, Loop )                         // IF Flag==1 THEN JR Loop

Leave a Reply