Forums

Topic: Petit Computer

Posts 9,341 to 9,360 of 9,618

SquareFingers

zeldafoursword wrote:

I don't understand which command should I use BUTTON or BTRIG

First question: Are you sure you will be checking the button status only once per frame, and every frame? If the answer is no, then use BUTTON(). If the answer is yes, and you want to know the instant that a button is pressed (but you don't care how long the button is held down, it's only the moment that it gets pressed that you want), then use BTRIG.

If you want auto-repeat, research the command BREPEAT, and use BUTTON(1). If you want to know when the button is released, you can use BUTTON(3). But these two, again, are only useful if you know you're scanning only once per frame, and every frame. In case you're interested, BUTTON(2) is the same as BTRIG(), and BUTTON(0) is the same as BUTTON().

SquareFingers

Petitlife935

if I have a CHR by the name of SOLDIER how can I put that into my game and what SPSET would I use for the first spot and the second spot?

Petitlife935

Discostew

Petitlife935 wrote:

if I have a CHR by the name of SOLDIER how can I put that into my game and what SPSET would I use for the first spot and the second spot?

You use the LOAD command as such....

LOAD "SPUx:SOLDIER", FALSE

where "x" is a number between 0 and 7, inclusive
and the FALSE at the end is just to prevent the load dialog from popping up.

As for how to access them, each sprite slot has up to 64 reference points sequentially (0 to 63, inclusive), so loading a sprite sheet would require that you add to your index the formula (x * 64). So, for instance, if you loaded your sprite sheet into slot 4, you would add 256 to your overall index (x * 64) -> (4 * 64) -> (256). If you loaded into slot 0, you'd add 0 (or nothing at all).

Discostew

Switch Friend Code: SW-6473-2521-3817

Petitlife935

How can I use LOCATE for SPSET
I am making a civil war stradegy game and I have a big map that takes up most of the screen but I made some sprites in CHRED and I want to know how to locate a sprite. here is the code for the example

ACLS:CLEAR
LOAD"SPU0:SOLDIER",FALSE
SPSET 0,0,0,0,0,1`

[Edited by Petitlife935]

Petitlife935

Discostew

Petitlife935 wrote:

How can I use LOCATE for SPSET
I am making a civil war stradegy game and I have a big map that takes up most of the screen but I made some sprites in CHRED and I want to know how to locate a sprite. here is the code for the example

ACLS:CLEAR
LOAD"SPU0:SOLDIER",FALSE
SPSET 0,0,0,0,0,1`

LOCATE is used to designate the position for text on the console layer, not for sprites. Do you mean setting their position? That would require using SPOFS

SPOFS <control number>,<x>, <y> [, <interpolation time>]

<control number> is the index you use when using SPSET
<x> increases from left to right
<y> increases from top to bottom
<interpolation time> (optional) is the time (in frames) to move the sprite from its current position to the position you specify as <x> and <y>. Leaving this blank will immediately move the sprite to the new position

Discostew

Switch Friend Code: SW-6473-2521-3817

Petitlife935

if i send a link to a CHRED will someone be willing to help me out ALOT and make a civil war animation??? If so it would really appriciated!

Petitlife935

Discostew

At this moment, other than some tweaks and more in-depth bug testing, all 8 Robot Masters and their attacks are implemented in my project.

Discostew

Switch Friend Code: SW-6473-2521-3817

mystman12

Is there anyway to make SPANIM play sprites backwards? I have a head that turns to the right in four frames, and I want it to be able to turn back, but it doesn't seem like I can use negative numbers, so the only thing I can think of doing is making another set of sprites with the animation in the backwards order. (Which I don't really want to do.)

I like makin' games!
Future Pinball games!
Petit Computer games!!
and SmileBASIC games!
Waiting for Kirby Air Ride 2. One day, it will come. One day...

X:

Discostew

mystman12 wrote:

Is there anyway to make SPANIM play sprites backwards? I have a head that turns to the right in four frames, and I want it to be able to turn back, but it doesn't seem like I can use negative numbers, so the only thing I can think of doing is making another set of sprites with the animation in the backwards order. (Which I don't really want to do.)

Yeah, SPANIM only works in a forward-sequential manner. You'd have to make another set of sprites to accomplish the same thing, or in the case I chose, develop your own sprite animation routine. I believe PTC3 doesn't have this limitation.

Discostew

Switch Friend Code: SW-6473-2521-3817

mystman12

Discostew wrote:

mystman12 wrote:

Is there anyway to make SPANIM play sprites backwards? I have a head that turns to the right in four frames, and I want it to be able to turn back, but it doesn't seem like I can use negative numbers, so the only thing I can think of doing is making another set of sprites with the animation in the backwards order. (Which I don't really want to do.)

Yeah, SPANIM only works in a forward-sequential manner. You'd have to make another set of sprites to accomplish the same thing, or in the case I chose, develop your own sprite animation routine. I believe PTC3 doesn't have this limitation.

Well that's kind of... Dumb, to put it bluntly. I had thought about manually moving the sprite back, but this game is just a silly thing I'm throwing together, so I'll just make more sprites. At least I can mirror them and don't have to make mirrored sprite sets too. It's just kind of annoying though because, unlike Infinite Office, which uses 16x16 or 8x8 (Can't remember right now) sprites, the sprite in question is a 64x64 sprite, so for a simple head turning animation forward and backward I'm gonna have to use up two pages of sprites.

I like makin' games!
Future Pinball games!
Petit Computer games!!
and SmileBASIC games!
Waiting for Kirby Air Ride 2. One day, it will come. One day...

X:

mystman12

Why oh why is sprite collision so overly complicated? In the game I'm working on I have a controllable character who can shoot, and a giant floating boss. All I want to do is make it so that when a bullet hits it, its health goes down. So, I tried making code like this:

FOR L=11 TO 31 'Those are all the possible numbers a bullet sprite could have, which allows for twenty on screen at a time.
IF SPHITSP(0,L)==TRUE THEN BOSSHEALTH = BOSSHEALTH - 1 '0 is the boss sprite number, L will obviously represent each bullet, and a side note, 1 is the player sprite number
NEXT

So that's my code, but the first time I tried running the game the boss health started plummeting. Now I just get an illegal function call, I guess because the bullet sprites don't always exist. (I have no idea why it didn't give me an error before) So what I need to know is what I'm doing right and wrong, and how to keep that command from crashing the game even with no bullet sprites. (I don't want to just place the bullets outside the screen because if the boss flies off screen I don't want it to ever accidentally hit the bullets and take damage)

Edit: Nevermind, I got it! I just used sprite groups to make it so the boss could only collide with bullets, and then used SPHITNO to SPCLR any bullets that hit it.

[Edited by mystman12]

I like makin' games!
Future Pinball games!
Petit Computer games!!
and SmileBASIC games!
Waiting for Kirby Air Ride 2. One day, it will come. One day...

X:

cactuswhale

hey guys I'm pretty new here and I'm making "BASEBALL STARING HOT DOGS!!" (which is actually the first three lines) I'm done making "sprites" and screen and don't know what the heck to do

[Edited by cactuswhale]

cactuswhale

cactuswhale

also IAMAPERSON I have a request for minecraft ds: the gameplay is pretty bland without music and pickaxes and other mining tools

cactuswhale

TobuKatsu

@DiscoStew Can you explain some basic platformer code? I know it was something like adding Y to mass and acceleration. I cant find any tutorials that explain it in either BASIC or without code.Its all C# or Java.

3DS FC : 4613 - 7463 - 3640
我的名字是TobuKatsu。Меня зовут ТобуКатсу. 私の名前はトブカツです。나는 이름을 케이린 입니다.
很高兴认识你。Очень приятно. よろしくお願いします。 만나서 반가워요.

Discostew

@TobuKatsu

It's not too difficult. I assume you have some understanding of the top-down concept (like the 2D Zelda games). Take that concept, but apply a downward acceleration to all valid object/entities/etc (basically, gravity). Because you are using acceleration, you also have to keep track of each object's velocity, adding the acceleration each game cycle. For instance, in MM2, most objects have a downward acceleration of 0.25 pixels per frame. If the sprite starts at 0 downward velocity, it'll be incremented by 0.25 pixels, and then the object's position is incremented by 0.25 pixels. The next frame adds acceleration again to velocity, making it 0.50. That gets applied to the position. Then another at 0.75 pixels, then 1 pixel, then 1.25 pixels, etc etc.

Because these objects will continually be accelerating downward, you check for collision with the background tiles or however you set this up. When colliding, you push the object in the opposite direction to line it up with the collision barrier (so that it won't be jittering along the boundary). So, at some point, you'd like your object to jump. Well, it's simple. Change the object's velocity to some negative number, like -3. As your code goes through the motions of applying acceleration to velocity, the object will initially move upward, but will arc until it reaches 0 velocity, to which it'll fall back down.

Not sure what else you need to know, but I hope this gets you started. Here's some example code.

CLEAR:CLS
OBJPOSY=0
OBJVEL=0
OBJACC=0.25
OBJSTOP=0

SPSET 0,0,0,0,0,0
SPHOME 0,8,16
SPOFS 0,128,OBJPOSY

@MYLOOP
VSYNC
SPOFS 0,128,OBJPOSY
IF BUTTON(2)==16 AND OBJSTOP==1 THEN OBJVEL=-9: OBJSTOP=0
IF OBJSTOP THEN GOTO @MYLOOP
OBJVEL=OBJVEL+OBJACC
OBJPOSY=OBJPOSY+OBJVEL
IF OBJPOSY>=160 THEN OBJPOS=160: OBJSTOP=1: OBJVEL=0
GOTO @MYLOOP

[Edited by Discostew]

Discostew

Switch Friend Code: SW-6473-2521-3817

TobuKatsu

@Discostew Thanks alot! It really helps! Tho, one more thing. How do i get the sprite to jump while moving? I added some left to right and when i press A and L/R it stops.

3DS FC : 4613 - 7463 - 3640
我的名字是TobuKatsu。Меня зовут ТобуКатсу. 私の名前はトブカツです。나는 이름을 케이린 입니다.
很高兴认识你。Очень приятно. よろしくお願いします。 만나서 반가워요.

Discostew

TobuKatsu wrote:

@Discostew Thanks alot! It really helps! Tho, one more thing. How do i get the sprite to jump while moving? I added some left to right and when i press A and L/R it stops.

That involves saving the button state and using bit masks. The example I made was for exact button presses. The actual result of BUTTON combines multiple button presses. Here are the values of each

Up — 1 = BIT0
Down — 2 = BIT1
Left — 4 = BIT2
Right — 8 = BIT3
A — 16 (you see that in the example)
B — 32
X — 64
Y — 128
L — 256
R — 512
Start — 1024
Select — 2048

Altogether is a total of 12 bits to form the result, from BIT0 to BIT11 (I stopped at BIT3, but you get the idea). If you are looking to read the Right on the D-Pad, you would do this

IF BUTTON() AND 8 THEN .....

If you are looking for input from both pressing up and to the right (which is a combination of 1 and 8)

IF BUTTON() AND 9 THEN ....

While that works, there is a problem. Because it is a combination of 1 and 8, the value is actually in the form of 1 OR 8, so when this line comes up to be executed, it'll pass if you press to the right OR up. So, we got to limit it.

IF (BUTTON() AND 9)==9 THEN ...

This will make sure that it MUST be up and to the right in order to proceed, rather than up OR right. Now, this works and all, but the problem is that what you read now may be different from what you read from the function again a little later. This is why it is good to save the button state each loop.

BT=BUTTON(0)

That way, you can check the state, and it won't change until your code loops around to read it again. This is really useful for Instant Press and Instant Release. I usually save them like such....

BT=BUTTON(0): 'Simply pressing the button
BTIP=BUTTON(2): 'Only shows results the moment you press a button. Instant Press
BTIR=BUTTON(3): 'Only shows result the moment you release a button. Instant Release

So, for what you want to do, you'd read from BT for D-Pad presses, and read from BTIP for pressing A for jumping (because if you read from BT for jumping with the example code I supplied earlier, he'd keep jumping the moment he'd reach the landing spot if you kept the button down).

IF BT AND 4 THEN .....(do what's needed for moving right
IF BTIP AND 16 THEN ..... (do what's needed for jumping)

[Edited by Discostew]

Discostew

Switch Friend Code: SW-6473-2521-3817

Sorry, this topic has been locked.