## Introduction: How to Make a Sprite Based Game for the 3DS and DSi Family

Hello. This is the follow up to my other instructable. If you haven't seen it yet, then I would advise you to see it. Today, I will show you how to make a sprite based game in Petit Computer. If you don't know what that means, then let me explain. A sprite is computer graphic that may be moved on-screen and otherwise manipulated as a single entity.

You will need some things:

• A DSi/DSi XL/3DS/3DS XL/2DS
• A little time**

*Petit Computer has been removed from the 3DS eshop. It is however on the DSi Shop.

**The required amount of time depends on how complex the game is and how much debugging it needs to be complete.

## Step 1: To the Code

Alright. The code. Here ya' go:

PNLTYPE "OFF"

X=110

Y=100

@START

CLS

PRINT "A SPRITE BASED GAME"

PRINT "PRESS ANY BUTTON TO BEGIN"

IF BTRIG()>0 THEN GOTO@GAME

WAIT 1

GOTO@START

@GAME

CLS

SPSET 0,64,0,A,0,0

SPOFS 0,X,Y

IF BUTTON()==4 THEN X=X-1 A=1

IF BUTTON()==8 THEN X=X+1 A=0

WAIT 1

GOTO@GAME

Okay, you're almost definitely wondering what all that is. I'll explain. At the top, it says PNLTYPE "OFF". That just says that the bottom screen will remain blank. Under @GAME, it says SPSET 0,64,0,A,0,0. SPSET is the command for displaying a sprite. All the stuff after it determines what the sprite will be, and what color scheme, and others. The first number is just the number that the sprite will be what is will be referred to as. The second number determines what sprite it is. The third number is the number that changes the color scheme. The fourth is the number that flips the sprite horizontally, which in our code an integer is used in it's place. The fifth number is the number that flips the sprite vertically. Finally, the sixth number makes the sprite seen as under text, or over text. SPOFS determines where the sprite is. The first number is the number of the sprite you want to move. The second and third are the X and Y position. The A=0 and A=1 at the end of the IF BUTTON() statements flips the sprite so it looks as if it is changing direction.

Optional:

If you want to set up boundaries for your sprite, you could add this bit of code:

IF X<0 THEN X=0

IF X>256 THEN X=256

This should be pretty easy to figure out what it does. Place it under the IF BUTTON()s.

## Step 2: More Complex...!

Let's try doing something more complex. How about a defense game where you guard something precious in the middle of the screen. Let's try it:

PNLTYPE "OFF"

X=110:Y=100:A=68:EXA=110:EYA=0:EXB=0:EYB=80:EXC=240:EYC=176:L=4:P=0:S=1

'Integers can be all in one line but have to be separated by colons

@START

CLS

PRINT "DEFEND THE STAR"

PRINT "PRESS ANY BUTTON TO BEGIN"

IF BTRIG()>0 THEN GOTO@RAND

WAIT 1

GOTO@START

@DIE

L=L-1

EXA=110:EYA=0:EXB=0:EYB=80:EXC=240:EYC=176

ACLS

GOTO@RAND

@POINT

P=P+1

EXA=110:EYA=0:EXB=0:EYB=80:EXC=240:EYC=176

ACLS

@RAND

R=RND(4)

@GAME

CLS

IF P>14 THEN S=2

IF P>29 THEN S=3

IF P>49 THEN S=4

SPSET 0,156,3,0,0,0

SPOFS 0,110,86

SPSET 1,A,4,0,0,0

SPOFS 1,X,Y

IF BTRIG()==1 THEN A=76 X=110 Y=68 B=1

IF BTRIG()==2 THEN A=68 X=110 Y=100 B=2

IF BTRIG()==4 THEN A=72 X=94 Y=84 B=3

IF BTRIG()==8 THEN A=64 X=126 Y=84 B=4

'Enemies

IF R==0 THEN SPSET 2,194,4,0,0,0

IF R==0 THEN SPOFS 2,EXA,EYA

IF R==0 THEN EYA=EYA+S

IF R==1 THEN SPSET 3,198,4,0,0,0

IF R==1 THEN SPOFS 3,EXA,EYC

IF R==1 THEN EYC=EYC-S

IF R==2 THEN SPSET 4,192,4,0,0,0

IF R==2 THEN SPOFS 4,EXB,EYB

IF R==2 THEN EXB=EXB+S

IF R==3 THEN SPSET 5,196,4,0,0,0

IF R==3 THEN SPOFS 5,EXC,EYB

IF R==3 THEN EXC=EXC-S

'Get Points

IF R==0 AND B==1 AND EYA>Y-16 THEN GOTO@POINT

IF R==1 AND B==2 AND EYC<Y+16 THEN GOTO@POINT

IF R==2 AND B==3 AND EXB>X-16 THEN GOTO@POINT

IF R==3 AND B==4 AND EXC<X+16 THEN GOTO@POINT

'Die

IF R==0 AND EYA>86 THEN GOTO@DIE

IF R==1 AND EYC<92 THEN GOTO@DIE

IF R==2 AND EXB>110 THEN GOTO@DIE

IF R==3 AND EXC<126 THEN GOTO@DIE

IF L<0 THEN GOTO@LOOSE

WAIT 1

GOTO@GAME

@LOOSE

ACLS

PRINT "YOU LOOSE. TRY AGAIN."

L=4

WAIT 120

GOTO@START

Okay, I hope that wasn't to sudden all of that crazy code. Under @RAND, it says R=RND(4). That means that the integer(being R) is equal to a random number between 0 and 3. I hope you can understand the rest. Especially because it's making simple statements like, "If you are on team blue, then go to the right of the room." Also, the picture is a QR code that you can scan to get the entire game. Instructions on scanning QRs:

• On the menu screen, tap File Management
• Then, tap read QR Codes
• Align the QR code within the red frame

## Step 3: Bonus!

Alright! Everybody likes bonus! Let's start out with saving your programs. To save your program, go to the run mode* in Write Program. Then, at the top of the bottom screen, there will be a button that says, "SAVE". Tap that. Then, write anything you want to name your program. It can be up to eight characters long. Now, onto making QR codes. The first thing you will do, is go to File Management. Then, tap Save to SD Memory Card. Then, select the file you want to make QR codes for. Then, tap Confirm in the bottom left of the screen. Then tap it again. Now, turn off your system and take the SD card out. Then, put the SD card in your computer. Now go to this site. Then click the big blue button that says, "SD Card files can be converted into QR codes." Then select your SD card and then go into private, then ds, then app, and then a file called 4B4E4145**. Then from there you can upload your file.

*Run mode is the part where the background is black

**That is what the file is called for me. It might be something different for you.

Participated in the
Coded Creations