informa
/
4 MIN READ
Blogs

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.

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

Latest Jobs

Treyarch

Playa Vista, Los Angeles, CA, USA
9.12.23
Senior Level Designer (Zombies)

PlayStation Studios Creative Arts

Petaling Jaya, Selangor, Malaysia
9.14.23
Lead/ Senior Asset Artist

Treyarch

Playa Vista, Los Angeles, CA, USA
8.22.23
Senior Gameplay Systems Engineer - Treyarch

High Moon Studios

Carlsbad, CA, USA
9.18.23
VFX Artist
More Jobs   

CONNECT WITH US

Explore the
Advertise with
Follow us

Game Developer Job Board

Game Developer

@gamedevdotcom

Explore the

Game Developer Job Board

Browse open positions across the game industry or recruit new talent for your studio

Browse
Advertise with

Game Developer

Engage game professionals and drive sales using an array of Game Developer media solutions to meet your objectives.

Learn More
Follow us

@gamedevdotcom

Follow us @gamedevdotcom to stay up-to-date with the latest news & insider information about events & more