Forums

Topic: Petit Computer Tutorials

Posts 1 to 20 of 101

Shadow1364

Ok, I've been going to the Petit Computer threads and noticed that many people don't know how to program anything. I made this to have people post tutorials for different functions in easy-to-follow messages. To keep it easy to browse I ask of you to not post questions about Petit Computer itself. This is only meant to be an easy reference guide. Thank you.

[Edited by theblackdragon]

FC: 1934-1622-0902

petitprogrammer

To load sprites and make them move use this coding. PS.CLS clears the screen of text so it's good to use at the start of programs.PPS.First you need to make sprites in PRG:CHU0. And set it to sprite mode also you'll notice the numbers 0-7 on the bottom where i put 0 just change it depending on what one you use and filename is what you sved it as.NOTE USING FALSE WHEN LOADING A PROGRAM WILL STOP IT FROM POSTING THE OK MESSAGE AT THE BEGINNING ON THE TOUCH SCREEN.
CLS
LOAD"SPU0:FILENAME",FALSE
SPSET 0,LOCATION,0,0,0,0,16,16
PRINT "Use the d-pad to move.
@LOOP
IF BTRIG()==1 GOTO @UP
IF BTRIG()==2 GOTO @DOWN
IF BTRIG()==4 GOTO @LEFT
IF BTRIG()==8 GOTO @RIGHT
GOTO @LOOP
@UP
SPREAD(0)X,Y
SPOFS 0,X,Y-16,60
GOTO @LOOP
@DOWN
SPREAD(0),X,Y
SPOFS 0,X,Y+16,60
GOTO @LOOP
@LEFT
SPREAD(0)X,Y
SPOFS 0,X-16,Y,60
GOTO @LOOP
@RIGHT
SPREAD(0)X,Y
SPOFS 0,X+16,Y,60
GOTO @LOOP

[Edited by petitprogrammer]

petitprogrammer

Shadow1364

@petitprogramer Thanx for starting us off! Now for the basics.
PRINT "HELLO" will display the word within the quotations -(hello)- on the screen
WAIT 120 will tell it to wait for 2 seconds. 60 is the equivalent of 1 second, and so on.

FC: 1934-1622-0902

ramstrong

Just a note that BGMPLAY takes a number, not a string. So, if you do something like BGMPLAY MENU right on top of your program without defining the content of MENU variable, it is equivalent to BGMPLAY 0. There are a lot of preset music that is very convenient to use. Look under Help Menu 10 - Preset Music. You have 30 songs to choose from.

Petit Computer Journal
Old site http://ramstrong.blogspot.com

Let's just call a spade, a spade.

ramstrong

DATA statements are nice. You can have a lot of data in compact form. I always use label and RESTORE command along with READ, like this:
RESTORE @MYDATA:FOR I=0 to 2:READ A$[I]:NEXT
...
END :' End of program

@MYDATA
DATA "HELLO","WORLD","FRIEND"

Also, you can have more than one, selected by RESTORE keyword. For example, you can RESTORE @MYDATA2 to select that particular data. This is useful because you can have @LEVEL1, @LEVEL2, @LEVEL3 and so on. Use RESTORE LEVEL$ to do so, after assigning appropriate entry to LEVEL$
@LEVEL1
DATA for level1
@LEVEL2
DATA for level2
@LEVEL3
DATA for level3

That being said, I'd just sooner assign the data to string variables directly. DATA keyword is specific to BASIC. You won't find it in any other languages.

Petit Computer Journal
Old site http://ramstrong.blogspot.com

Let's just call a spade, a spade.

Eel

[Edited by Eel]

Bloop.

<My slightly less dead youtube channel>

SMM2 Maker ID: 69R-F81-NLG

My Nintendo: Abgarok

ramstrong

SPRITE TUTORIAL

There is some confusion in how to use sprites in Petit Computer. I hope this text will make the matter a bit clearer. In Petit Computer, sprites can be thought of as independent objects, with its own layer and behavior. This means the graphic,BG,Console display will never be corrupted by sprites.

To use sprites, you must first define their existence. Just as you cannot use Arrays without DIM, you cannot use sprites without SPSET. This is all the command that you need to display sprites.

To animate sprites, you can use SPOFS, and SPCHR.
SPOFS: SPrite OFfSet is the way to position your sprites on screen. There is some confusion as to whether the sprite offset is relative value. It is not relative. It uses absolute measurements. You simply specify the x,y coordinate and the sprite will go there.

SPCHR: SPrite CHaRacter is the image (character number) that you want the sprite to be. For example: Boy is 64. Witch is 96. By changing this value, you can animate the sprite.

Those two commands are the only ones you need to use the sprites. But Petit Computer does provide you with convenient animation capabilities.

Think of the sprites as independent objects. When you tell the sprite to go somewhere via SPOFS, you can specify the time it takes to get there (in number of frames). If you want a sprite to go somewhere in 3 seconds, you can specify it using the time variable. Example: Move sprite 1 to location 15,60 in 180 frames: SPOFS 1,15,60,180. The sprite will do just that, unless there is another command that overrides it.

Think of it as "Set it and forget it" type of mechanism. You can do other things without manually adjusting the sprites. Another convenient feature is SPANIM
SPANIM: SPrite ANIMation lets you cycle animation automatically without your intervention. If you want to animate the walking cycle of the witch, you can do this: SPANIM 1,4,15 where 1 is the sprite number, 4 is the number of frames, and 15 is the number of frames each animation lasts.

Here's an example:
CLS:CLEAR

'BOY ANIMATION - AUTOMATIC
SPSET 2,64,0,0,0,0,16,16
SPANIM 2,4,15
SPOFS 2,0,0:MOVE TO 0,0
SPOFS 2,172,0,660:MOVE TO 172,0 IN 660 FRAMES

'WITCH ANIMATION - MANUAL
SPSET 1,96,0,0,0,0,16,16
FOR J=0 TO 10
FOR I=0 TO 3
VSYNC 15
SPCHR 1,96+I
SPOFS 1,J*16+I*4,16
NEXT
NEXT

'STOP BOY ANIMATION
SPANIM 2,1,0

You can tell the difference between the two easily, if you stop the program midway. The witch animation stops, while the boy animation keeps going.

Here's how you can use the automatic animation for your program. Notice the VSYNC 20. That means to cycle every 20 frames. If you use WAIT 20, the animation timing will be off.

@LOOP
B=BUTTON(0)
IF B AND 1 THEN D$="U"
IF B AND 2 THEN D$="D"
IF B AND 4 THEN D$="L"
IF B AND 8 THEN D$="R"

LOCATE 0,0:?D$
IF D$=="R" THEN A=64:SX=(SX+1)%16
IF D$=="D" THEN A=68:SY=(SY+1)%12
IF D$=="L" THEN A=72:SX=(SX+16-1)%16
IF D$=="U" THEN A=76:SY=(SY+12-1)%12

VSYNC 20:GOSUB @ANIM
GOTO @LOOP

@ANIM
SPCHAR 2,A
SPANIM 2,4,5
SPOFS 2,SX*16,SY*16,20
RETURN

And there you have it: Sprites that moves by DPad yet animates smoothly!

[Edited by ramstrong]

Petit Computer Journal
Old site http://ramstrong.blogspot.com

Let's just call a spade, a spade.

ramstrong

Duplicate definition (N, DIM) error?
You cannot redefine variables. You will get this error if you DIM a variable more than once, say, by running the program more than once. You can set up a special @INIT section like this:

'Program start
IF VARSET==FALSE THEN GOSUB @INIT
?"Program begins..."
END

@INIT
?"Initializing variables"
DIM A$[10]
VARSET==TRUE
RETURN

Or you can use CLEAR to clear off all variables in memory.

Petit Computer Journal
Old site http://ramstrong.blogspot.com

Let's just call a spade, a spade.

ramstrong

How to make your own music with BGM. Repost from Post #596

GrabSomeEyes wrote:

Cocobanana wrote:

Its going good.

I dont know how to use MML though:/

cough cough http://www.gamefaqs.com/boards/663843-petit-computer/63524945 cough
AH http://www.gamefaqs.com/boards/663843-petit-computer/63484250 CHOO!
Well then! Excuse me.

Edit:

neoxid500 wrote:

http://d.hatena.ne.jp/eidaht/20120630/1341016869

This was originally on the QR Code sharing thread but people are being CATZ... and keep asking about MMLS. Use this program to make 'em much easier and implement them in your games.

NOW STOP ASKING XD

While I love that program, it doesn't have nearly as many sounds as you get with just regular programming. I just use it to mess around with like Mario Paint. Any actual music making I'd recommend learning how to create in the editor. Plus, the satisfaction of hearing something you worked hard for.

I will add this program, which is straight from Help #44:
Once you have the MML string, put it into DATA. Unlike normal DATA statement, you don't need to READ it. Just need to Refer to it, similar in a way to refer to LABEL for GOTO/GOSUB. Make sure the DATA statements ends with DATA 0.

Some MML strings are too long, so split them into sections, let's say "PART A", "PART B", "PART C". We'll store the song into song#128. User defined song can be numbered 128 to 255.

In your main code, do this:
BGMSETD 128, @MMLDATA <== LABEL FOR MUSIC, CAN BE ANY LABEL
BGMPLAY 128 <== PLAYS THE MUSIC

Somewhere down in the DATA section:
@MMLDATA
DATA "PART A"
DATA "PART B"
DATA "PART C"
DATA 0 <== VERY IMPORTANT.

And that's it. Now find some MML strings out there and do it!

Petit Computer Journal
Old site http://ramstrong.blogspot.com

Let's just call a spade, a spade.

theblackdragon

@Sprite: our general Petit Computer thread is here if you'd like to ask that question. This thread is only for users to post their completed tutorials, I'm afraid. If you post your question to the proper thread, I'm sure someone will be nice enough to help you out. :3

BEST THREAD EVER
future of NL >:3
[16:43] James: I should learn these site rules more clearly
[16:44] LztheBlehBird: James doesn't know the rules? For shame!!!

X:

Linput

Hi i need help using and making stored data like this:

DATA"HELLO"

basically so i can just use the data to store text for l8r

Linput-3DS friend code: 4725-8494-2702
Pokemon White 2 pal-pad code: 1979 9213 55

I'm currently looking for some peeps to make SALLY a website, facebook, and email. If anyone does this u will be mentioned as a producer in the SALLY OS credits! :)

petitgamer

Retro_on_theGo wrote:

UUUGHGHH!!!!!! All the terms I don't understand and odd pairing of words! It huuuuurtss. I wish I had the time to make sense of this all and carefully read the posts here multiple times. Guess I'll have to wait until december to get serious with Petit Computer. D:

I know right?

3ds FC is 1934-1168-4523
fyi lucas is better than ness in any way shape or form.That is a coldhard fact.

smartman789

I have an idea.
Why don't you make a tutorial program and give the qr code for it?
I bet morphtroid could do this.

smartman789

Discostew

Made a tutorial about large backgrounds + scrolling about a month ago. Guess I might as well add a link to it here. Tutorial comes with complete source + QR code.

http://lazerlight.x10.mx/tut-large-bg-scroll/

Discostew

Switch Friend Code: SW-6473-2521-3817

smartman789

Discostew wrote:

Made a tutorial about large backgrounds + scrolling about a month ago. Guess I might as well add a link to it here. Tutorial comes with complete source + QR code.

http://lazerlight.x10.mx/tut-large-bg-scroll/

sorry, but my "parental controls" for the internet resticted that website.
could you display the qr code on this forum?

smartman789

Discostew

smartman wrote:

Discostew wrote:

Made a tutorial about large backgrounds + scrolling about a month ago. Guess I might as well add a link to it here. Tutorial comes with complete source + QR code.

http://lazerlight.x10.mx/tut-large-bg-scroll/

sorry, but my "parental controls" for the internet resticted that website.
could you display the qr code on this forum?

Untitled

Unfortunately, the "tutorial" portion is quite lengthy, and I don't think it would be appropriate to post it all here.

Discostew

Switch Friend Code: SW-6473-2521-3817

KAHN

Discostew wrote:

smartman wrote:

Discostew wrote:

Made a tutorial about large backgrounds + scrolling about a month ago. Guess I might as well add a link to it here. Tutorial comes with complete source + QR code.

http://lazerlight.x10.mx/tut-large-bg-scroll/

sorry, but my "parental controls" for the internet resticted that website.
could you display the qr code on this forum?

Untitled

Unfortunately, the "tutorial" portion is quite lengthy, and I don't think it would be appropriate to post it all here.

look at all the lengthy posts on this thread. HAVE NO SHAME.
post it... for reals... yo..

KAHN

Javo118

3DS FC: 2921-9808-6856

KAHN

this site should help. it's a site this guy is running. he's translating the japanese version into english, so it should be a good relevant read.
http://yakra13.site88.net/smiletuts.htm

[Edited by KAHN]

KAHN

Please login or sign up to reply to this topic