DSiWare Forum

Topic: Petit Computer

Showing 281 to 300 of 9,568

AuthorMessage
Avatar

DrKarl

281. Posted:

That sounds like you have the basic idea regarding control numbers down.

A note regarding your example. You are using SPHOME to position the sprite. Use SPOFS instead for most cases. It would look like this:
SPOFS 77,125,100

SPHOME is used to set the center point of rotation of the sprite for when you want to use the built in sprite rotation functions.

DrKarl

AuthorMessage
Avatar

Morpheel

282. Posted:

What you said about sprites is correct.
That code will create sprite 77 with CH 156 and make animate it with 4 frames, however (someone correct me if I'm wrong), SPHOME is used to set the "middle point" of the sprite, the one taken as a reference for when scaling and rotating it.
Example:
If your sprite is 16*16 pixels, you should set the SPHOME within these 16 pixels, taking the top-left corner as 0,0 and the bottom-right corner as 15,15.
You can still use higher or lower numbers, but if you scale or rotate it, it will be a mess.

Edit: I guess I was too slow xD

Edited on by Morpheel

Oops, no username pun.

Oh look! A Morphloggery.
Oh! eShop Gurus.

3DS Friend Code: 0173-1330-0080 | Nintendo Network ID: Abgarok

AuthorMessage
Avatar

KAHN

283. Posted:

DrKarl wrote:

That sounds like you have the basic idea regarding control numbers down.

A note regarding your example. You are using SPHOME to position the sprite. Use SPOFS instead for most cases. It would look like this:
SPOFS 77,125,100

SPHOME is used to set the center point of rotation of the sprite for when you want to use the built in sprite rotation functions.

good to know, thanks. also, whats the difference between BUTTON() and BTRIG() ? i looked for a difference in the manual, but i can't identify it, for some reason!

KAHN

3DS Friend Code: 1032-1301-2772 | Nintendo Network ID: Milkman12

AuthorMessage
Avatar

neoxid500

284. Posted:

Okay, so thanks to some very helpful advice (wow I'm stupid XD) I changed SPSET to SPCHR and my character no longer clips to the stop left. However, the intended movement is just causing my character to fidget around, unless I only press one direction. Help please? >.<

@PLYRCONTROLS
WAIT 1
SPREAD(0), X, Y
@MOVEBTTNS
IF BTRIG()==1 THEN GOTO @MOVEUP
IF BTRIG()==2 THEN GOTO @MOVEDOWN
IF BTRIG()==4 THEN GOTO @MOVELEFT
IF BTRIG()==8 THEN GOTO @MOVERIGHT
GOTO @MOVEBTTNS

@MOVEUP
SPOFS 0, X, Y - 16, 30
SPCHR 0, 140
SPANIM 0, 4, 20, 0
GOTO @PLYRCONTROLS
@MOVEDOWN
SPOFS 0, X, Y + 16, 30
SPCHR 0, 132
SPANIM 0, 4, 20, 0
GOTO @PLYRCONTROLS
@MOVELEFT
SPOFS 0, X -16, Y , 30
SPCHR 0, 136
SPANIM 0, 4, 20, 0
GOTO @PLYRCONTROLS
@MOVERIGHT
SPOFS 0, X +16, Y , 30
SPCHR 0, 128
SPANIM 0, 4, 20, 0
GOTO @PLYRCONTROLS
Also, if someone could help me figure out how to make it so that holding a button will make my character move in that direction, and then releasing would make it stop. I know it has something to do with the BUTTON() command, but after that I'm stumped. Here's what I changed to test it...

UPDATE: mmk so I finally got the moving buttons to work properly!! =DI took out the wait 1 and somehow it works now =P now to work on holding the button down,,,

Edited on by neoxid500

neoxid500

AuthorMessage
Avatar

KAHN

285. Posted:

@neoxid500 (<-- or everyone else)

how do i get SPREAD() to work properly? my only problem is the X,Y parts. i don't understand how the manual explains it.

@everyone
sorry i'm asking so many questions! im an amateur! XD

KAHN

3DS Friend Code: 1032-1301-2772 | Nintendo Network ID: Milkman12

AuthorMessage
Avatar

neoxid500

286. Posted:

0LD_SK0OL_PUNK wrote:

@neoxid500 (<-- or everyone else)

how do i get SPREAD() to work properly? my only problem is the X,Y parts. i don't understand how the manual explains it.

@everyone
sorry i'm asking so many questions! im an amateur! XD

[/div]

[/div]

Have you seen the amount of question's i've been asking? =P
Anyway, now that I have a fair comprehension on how SPREAD works I'd be happy to help. I'm sure by now after reading the other posts you've learned about the control number in the SPREAD string so I'll skip that. I've found that the SPREAD command works best to manipulate sprite movement in conjunction with the SPOFS command, however I'm sure you can use it in many other ways as well =)
So I'll walk you through my previous post's code to explain how the command works and how you can actually use the code I've posted above to allow sprite movement in your game.
@PLYRCONTROLS
SPREAD(0), X, Y
@MOVEBTTNS
IF BTRIG()==1 THEN GOTO @MOVEUP
IF BTRIG()==2 THEN GOTO @MOVEDOWN
IF BTRIG()==4 THEN GOTO @MOVELEFT
IF BTRIG()==8 THEN GOTO @MOVERIGHT
GOTO @MOVEBTTNS

@MOVEUP
SPOFS 0, X, Y - 12, 30
SPCHR 0, 140
SPANIM 0, 4, 20, 0
GOTO @PLYRCONTROLS

Now allow me to break this down for you. SPREAD(0) X, Y is used to identify the coordinate of my sprite (control number 0) and stores the x coordinate into "x" and the y coordinate into "y" (you may use any operable variable to store these numbers. Now, let's say that the first IF...THEN.. statement is met, and the program jumps to @MOVEUP. SPOFS 0, X, Y -16, 30 will then tell my sprite to go 16 spaces up over 30 frames (roughly half of a second). How does this work? Well, the variables "x" and "y" have already been stored as the sprites current position. So by subtracting 16 from the Y coordinate (you'd think it would be add 16 but no =P), the sprite then goes to the new coordinates (of course for diagonal movement, simply manipulate both variables). Finally, the program jumps back to SPREAD(0) X, Y where it re-retrieves the NEW coordinates after adding the 16. So if "x" and "y" were both 8, the new stored coordinates are now (8,24) so the next time the up button is pressed, the new value would be (8, 40) as opposed to (8, 24) again if the program didn't re-retrieve the sprite's coordinates.
Sorry it got lengthy at the end there but I hope this helped =)

Edited on by neoxid500

neoxid500

AuthorMessage
Avatar

KAHN

287. Posted:

ok, i think i might understand. the parenthesis are for the control number, and the X,Y parts are for the X,Y coordinates, right? ok, so i replace the X and Y with numbers(the coordinates), but then i run the program, and this shows up:

illegal function call (2, SPREAD)

what am i doing wrong? should the X,Y coordinates i place in be the same as the X,Y coordinates i place in SPOFS?

KAHN

3DS Friend Code: 1032-1301-2772 | Nintendo Network ID: Milkman12

AuthorMessage
Avatar

DrKarl

288. Posted:

0LD_SK0OL_PUNK wrote:

ok, i think i might understand. the parenthesis are for the control number, and the X,Y parts are for the X,Y coordinates, right?

NOTE: I have not yet used SPREAD, so this may not be correct.

I am pretty sure that you must provide a control number and two variables for the X and Y. After SPREAD finishes, it will set X and Y to the X and Y coordinates of the sprite corresponding to that control number.

For example:

SPSET 1,10,1,0,0,1
SPOFS 1,15,25

XLOCATION = 0
YLOCATION = 0

SPREAD(1),XLOCATION,YLOCATION
PRINT STR$(XLOCATION) + "," + STR$(YLOCATION)


If my reading of the SPREAD command is correct, this program would print out: 15,25

Edited on by DrKarl

DrKarl

AuthorMessage
Avatar

KAHN

289. Posted:

DrKarl wrote:

0LD_SK0OL_PUNK wrote:

ok, i think i might understand. the parenthesis are for the control number, and the X,Y parts are for the X,Y coordinates, right?

[/div]

NOTE: I have not yet used SPREAD, so this may not be correct.

I am pretty sure that you must provide a control number and two variables for the X and Y. After SPREAD finishes, it will set X and Y to the X and Y coordinates of the sprite corresponding to that control number.

For example:

SPSET 1,10,1,0,0,1
SPOFS 1,15,25

X = 0
Y = 0

SPREAD(1),X,Y
PRINT STR$(X) + "," + STR$(Y)


If my reading of the SPREAD command is correct, this program would print out: 15,25

t

if i'm supposed to use variables, what kind? integer variable? letter variables? give an example.

KAHN

3DS Friend Code: 1032-1301-2772 | Nintendo Network ID: Milkman12

AuthorMessage
Avatar

Fidgit

290. Posted:

So I'm trying to learn how to use this app and am too impatient to wait for the manual to come out. I figured I'd start simple and am having some issues. I wanted to try to make a Yahtzee game. To start I am trying to get the dice rolling random numbers and to press A to roll again, but it isn't working the way it should. I know its a completely stupid question, but I don't know anything about basic, so if someone doesn't mind, could you tell me where I messed up?
Heres what I did:
CLS
@ROLL
DIE1 = RND(6)
DIE2 = RND(6)
DIE3 = RND(6)
DIE4 = RND(6)
DIE5 = RND(6)
PRINT "DIE 1: "; DIE1
PRINT "DIE 2: "; DIE2
PRINT "DIE 3: "; DIE 3
PRINT "DIE 4: "; DIE4
PRINT "DIE 5: "; DIE5
END
PRINT "PRESS A TO ROLL AGAIN."
IF BTRIG() == 16 THEN GOTO @ROLL

The dice all do what they should, but it never rerolls them when I press a. I've tried playing around with things to test them, but using buttons always gives me a hard time. thanks.

Edited on by Fidgit

I am currently making sprite, playing Minecraft, johnny Kung Fu and am awaiting Kingdom Hearts and New SMB 2. Not sure which I'll choose....cash is low these days.
Walking Dead still the best show on tv!

AuthorMessage
Avatar

DrKarl

291. Posted:

0LD_SK0OL_PUNK wrote:

if i'm supposed to use variables, what kind? integer variable? letter variables? give an example.

I did give an example. X and Y are perfectly valid variable names. :) For the record, they are integer variables, as each pixel location on the screen is represented with two integers. One for the X and one for the Y.

If it makes it easier, replace X and Y with XLOCATION and YLOCATION. I have edited the example above to reflect this.

DrKarl

AuthorMessage
Avatar

DrKarl

292. Posted:

Fidgit wrote:

CLS
@ROLL
DIE1 = RND(6)
DIE2 = RND(6)
DIE3 = RND(6)
DIE4 = RND(6)
DIE5 = RND(6)
PRINT "DIE 1: "; DIE1
PRINT "DIE 2: "; DIE2
PRINT "DIE 3: "; DIE 3
PRINT "DIE 4: "; DIE4
PRINT "DIE 5: "; DIE5
END
PRINT "PRESS A TO ROLL AGAIN."
IF BTRIG() == 16 THEN GOTO @ROLL

A couple of things look fishy. First, the END command will completely end the program. You are ending the program before you are allowing the user to press the button.

Next, you probably are noticing that your die rolls are between 0 and 5. You will need to add a 1 : DIE1 = RND(6) + 1

Third, since DIE1-DIE5 are integers, to print them you will need to use STR$. Use the plus sign (+) to link them, like this: PRINT "DIE 1: " + STR$(DIE1)

Edited on by DrKarl

DrKarl

AuthorMessage
Avatar

Wheels2050

293. Posted:

How is the sprite editor? The more I think about it, the more fun this sounds, but I'm somewhat artistically-challenged, to say the least.

I used to have a blog link here. I'll put it back up when the blog has something to read.

AuthorMessage
Avatar

DrKarl

294. Posted:

I took the liberty of rewriting the Dice program. I included a couple of extra tips to help you get up to speed with BASIC

Untitled

CLEAR
DIM DIE(6)

@MAINLOOP

CLS
GOSUB @ROLLDICE
GOSUB @DISPLAYDICE

PRINT "PRESS А TO ROLL AGAIN"
PRINT "PRESS Б TO QUIT"

@BUTTONLOOP
IF BTRIG() == 16 THEN GOTO @MAINLOOP
IF BTRIG() == 32 THEN GOTO @DONE
GOTO @BUTTONLOOP

@DONE
END

''''''''''' SUB - ROUTINES ''''''''''''''''''

@ROLLDICE

FOR I = 1 TO 5
DIE(I) = RND(6) + 1
NEXT

RETURN

@DISPLAYDICE

FOR I = 1 TO 5
PRINT "DIE " + STR$(I) + ": " + STR$(DIE(I))
NEXT

RETURN

Edited on by DrKarl

DrKarl

AuthorMessage
Avatar

ejamer

295. Posted:

DrKarl wrote:

Fidgit wrote:

...
PRINT "DIE 1: "; DIE1
...

...
Third, since DIE1-DIE5 are integers, to print them you will need to use STR$. Use the plus sign (+) to link them, like this: PRINT "DIE 1: " + STR$(DIE1)

No - the original print statements should be fine.

I agree with the rest of what was said, but worry that you might get a lot of results printed when you press A with the current code. One cycle of that loop is extremely quick. Won't you see the dice printed multiple times with the updated code? Something as simple as a WAIT 60 would probably help, although I'm sure it's not the best solution.

Edit: Tested the updated program, and when you press A the dice are rolled and printed a number of times, not just once. This happens so quickly that you might not care (especially with such a small program) but I think that it's important to realize it happens. To test you can add this line of code just above the final RETURN statement:

NUM=NUM+1: PRINT "This is roll number: ";NUM

On average, every time I press the A button the dice are rolled 5 times. If you make a Yahtzee knock-off, that might not be desirable behavior.

Edited on by ejamer

ejamer

Nintendo Network ID: ejamer

AuthorMessage
Avatar

neoxid500

296. Posted:

Wheels2050 wrote:

How is the sprite editor? The more I think about it, the more fun this sounds, but I'm somewhat artistically-challenged, to say the least.

[/div]

The sprite editor give you 16 colors to work with, however those colors can be changed to any hue of your liking. It may take a while to learn it, but once you have it done it will give you a great sense of accomplishment one you've completed something. =)

P.S. Can anyone help with making an AI that targets the player? The player's coordinates are already set to the variables X and Y so bullets can be shot at the character current position if he stands still. But making an AI... that's kind of above my head XD, I'm also not really sure how to make things randomly spawn or appear in a random area. Help? Some useful commands for this would be helpful =) ty!

Edited on by neoxid500

neoxid500

AuthorMessage
Avatar

Fidgit

297. Posted:

Thanks for the help. I completely forgot that I could combine the instructions for all the die instead of writing each one out.... I had some issue with it printing multiple times when I was trying to figure it out myself, but Dr. Karl's way works just fine. Now I'm going to try getting it to reroll only the dice you select, if I can. Don't be surprised if it ends up with more confusion and questions. Maybe if I can get the hang of it I'll try for a touch screen version, it seems like it would play better that way,but I've heard playing around with the touch screen is tricky...one step at a time! Thanks again for all the help!.

I am currently making sprite, playing Minecraft, johnny Kung Fu and am awaiting Kingdom Hearts and New SMB 2. Not sure which I'll choose....cash is low these days.
Walking Dead still the best show on tv!

AuthorMessage
Avatar

DrKarl

298. Posted:

ejamer wrote:

No - the original print statements should be fine.

Regardless, the ; is not necessary. Also, I feel that it is important to get in the habit of using str$ when printing integers. What if the programmer needs to tack additional text after the integer is printed? They will need to have wrapped the integer in str$ in order to do so.

ejamer wrote:

Edit: Tested the updated program, and when you press A the dice are rolled and printed a number of times, not just once. This happens so quickly that you might not care

I am not seeing this. Did you scan my QR code? If you just typed in the code, perhaps you made a typo? If you hold down A, do numbers just keep flickering by? With my machine here, holding down A only produces the numbers once.

DrKarl

AuthorMessage
Avatar

DrKarl

299. Posted:

Fidgit wrote:

Don't be surprised if it ends up with more confusion and questions.

No worries. :) One step at a time.

I love Yahtzee. A touch screen version would be awesome, even if it is just a solitaire experience for high score.

DrKarl

AuthorMessage
Avatar

ejamer

300. Posted:

DrKarl wrote:

ejamer wrote:

No - the original print statements should be fine.

[/div]

Regardless, the ; is not necessary. Also, I feel that it is important to get in the habit of using str$ when printing integers. What if the programmer needs to tack additional text after the integer is printed? They will need to have wrapped the integer in str$ in order to do so.

[/div]

Using the STR$() function is a fine idea. I'm not suggesting otherwise. But it's not necessary.
If you want to add additional text after the integer, you can use the same format:

PRINT "text ";INTEGER;" more text"

The key is using the semi-colon between each change in datatype.

I am not seeing this. Did you scan my QR code? If you just typed in the code, perhaps you made a typo? If you hold down A, do numbers just keep flickering by? With my machine here, holding down A only produces the numbers once.

Used your code to test, via the QR code, but the observation was based on my own experience. You won't (normally) see it happen because the code executes extremely quickly - there is virtually no visible sign outside of a minor flicker. It happens though: add the line of code I posted in my edit and test for yourself.

The full cycle of code is very likely to run multiple times when you press the button, meaning the dice will be rolled and printed multiple times. In most cases this won't matter, but sometimes you might want to perform an action exactly once in response to a button press.

Also, if nitpicking about what you probably should do then:

  • use IF-GOTO structure instead of IF-THEN GOTO
  • likely smarter to take button input as a variable and then process the variable with IF statements instead of reading a new button
  • use a VSYNC 1 statement before the BTRIG statement to avoid the duplication error

I'll post in a corrected QR code shortly.

Untitled

Edited on by ejamer

ejamer

Nintendo Network ID: ejamer