Sponsored By

The first video game I've ever programmed.

Check out this stupidly simple video game. I put a lot of sweat, blood, and tears into it.

Joshua Williams, Blogger

November 23, 2016

5 Min Read
Game Developer logo in a gray background | Game Developer

Hello Gamesutra community! This is the first "game" I have ever programmed. It runs off a language called DCPU-16. It's an offshoot of a game Notch/mojang was making called 0x10c. It's very simple, but it took around 12 hours of work. Copy and paste the code into http://www.dcpu-ide.com/ ;

I've included the code below; this is what you should copy and paste into the website's text editor, then hit debug, then hit run in the upper lefthand corner. Enjoy!

; --------------------------------------------
; Title: Don’t touch the cube ;D!
; Author: Josh Williams
; Date: 11/22/2016
; Version: 0.01
; --------------------------------------------
; Description:
; This program demonstrates boundaries, objects, and keyboard input. 
; It is targeted at the DCPU version 1.7.
; --------------------------------------------


hwn i ; Get the list of attached hardware
set j, 0 ; Count
:loop
hwq j ; Step 1: Get info
ife a, 0xf615 ; If monitor...
set pc, display_detected
ife a, 0x7406 ; keyboard...
set pc, keyboard_detected
ife a, 0xb402 ; clock...
set pc, clock_detected 
:continue
add j, 1 ; Count++
ife j, i ; When finished iterating
set pc, initialize_display ; Start setting up the display routine
set pc, loop


:display_detected
set [display_address], j ; set the address
set pc, continue ; then continue finding stuff
:keyboard_detected
set [keyboard_address], j ; set the address
set pc, continue ; then continue finding stuff
:clock_detected
set [clock_address], j ; set the address
set pc, continue ; then continue finding stuf

:initialize_display ; Detection routine finished, loop or do more stuff here
set j, 0x8000
set i, hello_world ; letter counter; start of video memory
:next_char
set a, [i] ; a = letter
ife a, 0x0000 ; if next character is 0x0000
set pc, draw_karet ; you're done
bor a, 0x4600 ; else, set foreground color for letter
set [j], a ; toss it to the memory location
add i, 1 ; move to next char
add j, 1 ; move to next video memo location
set pc, next_char ; go to next char
:draw_karet
set [j],0x4F1b
:draw_final
set a, 0 ; MEM_MAP_SCREEN mode
set b, 0x8000 ; address of memory to be used
hwi [display_address] ; send interrupt
set b, 5 hwi [clock_address] ; start clock
set i, 0
set x, 1
set y, 1
set j, 0x0020
set c, 0
set b, 0
:inf_loop

set a, 1 ; get clock ticks
hwi [clock_address] ; store ticks in c
ife c, [last_tick]
set pc, inf_loop

:main


hwi [keyboard_address]
ife c, 0x0080 ; UP
set pc, Up

ife c, 0x0081 ; DOWN
set pc, Down

ife c, 0x0082 ; LEFT
set pc, Left

ife c, 0x0083 ; RIGHT
set pc, Right

ife c, 0
set pc, inf_loop

:Up
sub [Bally], 1
ife [Bally], -1 ; Check for the upper screen edge
set [Bally], 0
ife [Bally], 7 ; Check for object
ife [Ballx], 29
set [Bally], 8

set pc, animate

:Down
add [Bally], 1
ife [Bally], 12 ; Check for the lower screen edge
set [Bally], 11

;ife [Bally], 8 ; End of allowed free roaming
;set [Bally], 7


ife [Bally], 7
ife [Ballx], 29 ; check for object
set [Bally], 6

;ife [Bally], 7
;ife [Ballx], 30
;set [Bally], 6

;ife [Bally], 7
;ife [Ballx], 31
;set [Bally], 6

set pc, animate

:Left
sub [Ballx], 1
ife [Ballx], -1 ; Check for the left screen edge
set [Ballx], 0
ife [Bally], 7
ife [Ballx], 29 ; RIGHT OBJECT BOUNDARY
set [Ballx], 30

set pc, animate

:Right
add [Ballx], 1
ife [Ballx], 32 ; Check for the right screen edge
set [Ballx], 31

ife [Bally], 7
ife [Ballx], 29 ; RIGHT OBJECT BOUNDARY
set [Ballx], 28

:animate
ife [currentAnimation], 0xF031
set pc, drawZero
set y, [Bally] ; else move ball
mul y, 0x0020
add y, [Ballx]
add y, 0x8000
set [currentAnimation], 0xF031 ; remember the animation
set [y], 0xF031 ; draw 1
set pc, inf_loop

:drawZero
set y, [Bally] ; else move ball
mul y, 0x0020
add y, [Ballx]
add y, 0x8000
set [currentAnimation], 0xF030 ; remember the animation
set [y], 0xF030 ; draw 0

set pc, inf_loop

; Data
:display_address
DAT 0xFFFF
:keyboard_address
DAT 0xFFFF
:clock_address
DAT 0xFFFF
:hello_world
DAT " Don't touch the red cube... pretty please ;D ", 0x0000
:last_tick
DAT 0x0000
:Ballx
DAT 0x0000
:Bally
DAT 0x0000
:currentAnimation
DAT 0x0000

Read more about:

Blogs
Daily news, dev blogs, and stories from Game Developer straight to your inbox

You May Also Like