Redirection

Redirection

Not enough ratings
Creating custom Robot Arcade games
By Dan200
A guide to creating custom games for the Redirection Robot Arcade
   
Award
Favorite
Favorited
Unfavorite
Getting Started
As you play through Redirection, you'll unlock various small arcade games you can play in the Robot Arcade: literally a Robot re-programmed as an arcade machine! This guide will teach you how to write your own game disks to play in the Robot Aracde.

Robot Arcade games are written using Lua[www.lua.org]. If you're unfamiliar with Lua, check out the guide Learn Lua in 15 minutes[tylerneylon.com], it's one of the easiest programming languages around to get started with.

Creating your first game
  1. Select Mod Editor from the Main Menu
  2. Select Create New, and type in a name for your game (you can rename it later)
  3. Select Open Mod Folder
  4. Download the Arcade Game Template[www.redirectiongame.com], and extract it into the mod's assets folder
  5. Go back to the Main Menu, select Robot Arcade and verify that your new game appears in the game list.

Writing your game
Each Arcade Game is described by a .disk file, which describes a floppy disk, and points to a folder containing it's contents. Each disk contains a lua file named boot.lua, which contains the code the Robot will run on startup. A really simple game looks like this:

require "system" -- Get the devices we need gpu = system.getDevice( "gpu" ) gamepad = system.getDevice( "gamepad" ) while true do -- Clear the screen gpu.clear( 0 ) -- Draw some text gpu.drawText( 0, 0, "HELLO WORLD" ) if gamepad.getButton( 0 ) then gpu.drawText( 0, 6, "A is held" ) end -- Sleep for one frame system.sleep( 0 ) end

You can use the require function and the io library to access other files on the disk. At any time in the Robot Arcade, you can press Ctrl + R to reboot the Robot and see your current changes.

To interact with the display, the speakers or the gamepad, just call methods on the respective device objects. A typical game will check inputs at the start of each frame, perform some action, then draw some graphics to the screen. For complete documentation on the methods that are available to you, read the next section, or take a look at the Sample Game on the Steam Workshop.
Working with Devices
Each Arcade Robot comes equipped with a monochrome display, a simple GPU, a speaker with 2 audio channels, and a 2-axis 2-button gamepad. You can access each of these devices by calling system.getDevice( type ) at startup and calling methods on the returned object. A summary of their most useful methods follows:

Gamepad Methods
The standard Robot gamepad has 2 axes and 2 buttons, you can access their values as so:
  • gamepad.getButton( index )
    Returns whether the specified button on the gamepad is currently held down. 0 is the A button and 1 is the B button.

  • gamepad.getAxis( index )
    Returns the value of specified axis on the gamepad in the range -1 to 1. 0 is the X axis and 1 is the Y axis.

Display Methods
The standard Robot display has a resolution of 64x64 black and white pixels. It holds a reference to an image object representing it's current screen contents, which you can draw to with the GPU.
  • display.getImage()
    Returns the image object currently being shown on the display. Use this with gpu.setTarget() to resume drawing to the display after targetting a different image.

  • display.setImage( image )
    Changes the image being shown on the display. The size of the image must match the display resolution.

GPU Methods
The standard Robot GPU contains hardware accelerated 2D drawing methods for writing to images. By default, the GPU will target the display image, so calling GPU methods will write to the screen. All positions passed into GPU drawing functions are integer pixel coordinates, with 0,0 in the top left. All colors passed into GPU drawing functions are integer color indices, where 0 is black and 1 is white.
  • gpu.clear( [color] )
    Sets all the pixels on the GPU target to color, or 0 if unspecified.

  • gpu.drawPixel( x, y, color )
    Draws a single pixel at the location x, y.

  • gpu.drawLine( x1, y1, x2, y2, color )
    Draws a line between the locations x1, y1 and x2, y2.

  • gpu.drawTriangle( x1, y1, x2, y2, x3, y3, color )
    Draws a filled triangle between the locations x1, y1,x2, y2 and x3, y3.

  • gpu.drawTriangleOutline( x1, y1, x2, y2, x3, y3, color )
    Draws an unfilled triangle between the locations x1, y1,x2, y2 and x3, y3.

  • gpu.drawBox( x1, y1, width, height, color )
    Draws a filled box at the location x1, y1 width pixels wide and height pixels tall.

  • gpu.drawBoxOutline( x1, y1, x2, y2, x3, y3, color )
    Draws a unfilled box at the location x1, y1 width pixels wide and height pixels tall.

  • gpu.drawEllipse( x1, y1, width, height, color )
    Draws a filled ellipse (or circle) at the location x1, y1 width pixels wide and height pixels tall.

  • gpu.drawEllipseOutline( x1, y1, x2, y2, x3, y3, color )
    Draws an unfilled ellipse (or circle) at the location x1, y1 width pixels wide and height pixels tall.

  • gpu.drawText( x, y, text )
    Draws the string text at the location x, y.

  • gpu.measureText( text )
    Returns the width and height of the string text in pixels, without drawing.

  • gpu.newImage( width, height[, color] )
    Creates a blank image width pixels wide and height pixels tall, filled with the color color, or 0 if unspecified.

  • gpu.loadTGA( stream )
    Loads a TGA file from an I/O stream and returns the created image object. The stream must be opened in the rb mode and the file must be saved in indexed color mode. The following code will load and draw an image:
    local image = gpu.loadTGA( io.open( "image.tga", "rb" ) ) gpu.drawImage( 0, 0, image )

  • gpu.drawImage( x, y, image )
    Draws the image image at the location x, y.

  • gpu.drawMap( x, y, map, tileset )
    Draws the image map at the location x, y as a tilemap, using tile images from the image tileset. For each pixel in map, the color index is extracted and the corresponding tile image is drawn from tileset, which should be a grid of 16x16 equally-sized tile images. This is useful for creating game levels.

  • gpu.setTarget( image )
    Sets the GPU target to image, so subsequent draw calls will write to this image instead of the display. Call gpu.setTarget( display.getImage() ) to re-target the display.

  • gpu.setOffset( x, y )
    Causes all subsequent draw calls to be offset x pixels horizontally and y pixels vertically. Call gpu.setOffset( 0, 0 ) to reset the offset.

  • gpu.mapColor( inColor, outColor )
    Causes all subsequent attempts to draw the color inColor to result in outColor being drawn to the GPU target. Call gpu.mapColor( inColor, inColor ) to reset the mapping.

  • gpu.setTransparentColor( color )
    Causes all subsequent attempts to draw the color color (after remapping) to leave the target pixel unchanged. Call gpu.setTransparentColor( nil ) to disable transparency.
The following methods operate on image objects returned by GPU methods:
  • image:getSize()
    Returns the width and height of the image in pixels.

  • image:read( x, y[, length] )
    If length is specified, returns a string of color values starting at the coordinates x,y, otherwise, returns the color of the pixel at the coordinates.

  • image:write( x, y, value )
    If value is a string, writes the bytes from the string into the image starting at the coordinates x,y. If it is a number, sets the color of the pixel at the coordinates.

  • image:flipX()
    image:flipY()
    image:rotate90()
    image:rotate180()
    image:rotate270()
    Flips or rotates the image.

  • image:copy()
    Returns a copy of the image.

  • image:sub( x, y, width, height )
    Returns a new image object representing a sub-section of the image.

Speaker Methods
The standard Robot speaker has 2 audio channels, capable of emitting basic audio waveforms.
  • speaker.play( sound[, channel] )
    Plays the sound sound on the audio channel channel. If no channel is specified, any free channel will be used. Returns the audio channel that was chosen, or nil if none were available. Sounds are described using tables with the following keys:

    Key
    Description
    Default Value
    frequency
    The starting frequency of the sound, in Hz
    Required
    duration
    The duration of the sound, in seconds
    Required
    waveform
    The waveform of the sound. Valid values are "square", "triangle", "sawtooth" and "noise"
    "square"
    volume
    The peak volume of the sound, in the range 0 to 1
    1
    attack
    The time taken for the sound to fade in, in seconds
    0
    decay
    The time taken for the sound to fade out, in seconds
    0
    slide
    The rate at which the frequency of the sound changes over time, in Hz per second
    0
    duty
    The duty cycle of the waveform, in the range 0 to 1. Only affects square waves.
    0.5

  • speaker.queue( sound, channel )
    Plays the sound sound on the audio channel channel, once the current sound and all previously queued sounds are completed.

  • speaker.stop( [channel] )
    If channel is specified, stops all sounds playing on this channel. Otherwise, stops all sounds on all channels.
Publishing your Game
When you're happy with your game and ready to share it with the world, it's time to publish your mod to the Steam Workshop! But first, make sure you've done the following:
  1. Give your disk a label. Do this by editing the .png image that sits alongside the .disk file in your mod assets. This will be shown on the front of the Floppy Disk on the game selection screen.

  2. Create a thumbnail image for your mod. This should be named thumbnail.png, sized 852x480, and placed in the root directory of your mod. This will be shown on the Steam Workshop.

  3. If you have not done so already, Accept the Steam Workshop Contributor Agreement. You must do this before other people can see your Mod!
Then, when you're ready, select your mod in the Mod Editor and press the Publish Mod button! Keep an eye on the subscribers and comments on your mod to see how other players react to it. If you make any changes to your mod after publishing it, just click Publish Mod again to upload the new version. Your mod will automatically update for your subscribers.

Have fun!
3 Comments
Dan200  [author] 9 Jan, 2017 @ 7:01am 
Fixed. Thanks!
mseyne 9 Jan, 2017 @ 6:22am 
Typo : Ctrl-R to reboot and not only R and gpu.drawEllipseOutline function for unfilled ellipse not filled.
Winner丨Mr. bad 6 Nov, 2016 @ 7:44am 
good