It is currently Fri May 25, 2018 5:47 pm

 All times are UTC - 7 hours

 Page 3 of 3 [ 37 posts ] Go to page Previous  1, 2, 3
 Print view Previous topic | Next topic
Author Message
 Post subject: Re: Learning Action Game BasicsPosted: Sun Aug 20, 2017 3:00 am

Joined: Tue May 28, 2013 5:49 am
Posts: 972
Location: Sweden
tokumaru wrote:
Pokun wrote:
The player teleports far above the ceiling whenever he bumps his head into it.

Don't forget to account for the heights of the player and metatiles.

Then what's the purpose of this EOR? Isn't it supposed to take care of the metatile width/height according to your own post in the linked thread? Player width/height is already accounted for in the code (currently hard-coded to 8 because the replacement graphics I'm currently using is a single 8x8 sprite at the moment) and works as it should.

I tried skipping EOR and used AND instead but subtracted metatile height:

Negative Y-velocity (for ceilings) Ejection:
Code:
@collision_solid_n:
lda #\$00
sta p1_vy+0
sta p1_vy+1             ;stop velocity when banging head in ceiling

sta p1_y+0
lda p1_y+1
and #\$0F
sec
sbc #\$10                ;subtract metatile height
sta temp+1
lda p1_y+1
clc
sta p1_y+1              ;eject from tile, Y = Y + (Y AND \$0F) - metatile_h

Now it seems to work, but if you jump too hard into a ceiling you will teleport through the metatile and appear on top of it. I don't get it.

 Attachments: actiongame.7z [3.71 KiB] Downloaded 26 times
Top

 Post subject: Re: Learning Action Game BasicsPosted: Mon Aug 21, 2017 9:06 am

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 874
Location: cypress, texas
tokumaru wrote:
I believe I use a similar trick when calculating sprite coordinates, to compensate for the fact that sprites are positioned one scanline lower than the Y coordinate specified in their OAM entries. Instead of doing SpriteY = ObjectY - CameraY, I do SpriteY = ObjectY - CameraY - 1 by putting a CLC before the subtraction, instead of the usual SEC.
That's exactly what Kasumi taught me to do, I think; well he did teach me to use a clc when you want to always subtract one more. Pokun was talking about not implementing adding one to some value. Should have written something like, "invert the carry from its normal setting to always subtract or add one more; Kasumi taught me that."
edit: tokumaru, thanks for sharing that. I feel that what I should have written would have been more honest.

Top

 Post subject: Re: Learning Action Game BasicsPosted: Mon Aug 21, 2017 10:05 am

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 874
Location: cypress, texas

edit: using FCEUX 2.2.3

Top

 Post subject: Re: Learning Action Game BasicsPosted: Wed Aug 23, 2017 4:43 pm

Joined: Tue May 28, 2013 5:49 am
Posts: 972
Location: Sweden
Thanks, I didn't know what the trace logger was for. I might try that next time I run into this kind of problem.

I think I know what's causing it though. When hitting the ceiling I just zero out velocity, but I don't cancel the jumping. If the player continues to hold jump the player character will be forced through the ceiling and eventually snap up on top of it.
The jetpack problem I had earlier wasn't entirely fixed as I haven't made it so the jump will be cancelled if you release the button.

Every frame that the A button is pressed, I set Y-velocity to a certain value which launches the player character into the air. If the player was grounded I also reset the jump timer at this point, otherwise I just set Y-velocity. Also every frame the player is in the air, gravity is constantly accelerating the player downwards and also decreasing the jump timer. When the jump timer reaches zero the A button is ignored, and the player can't continue the jump anymore. The gravity will eventually become stronger and the player will fall, resulting in a nice parabola shaped jump.

To cancel the jump I guess I may need another variable that keeps track of if the player is jumping or falling (regardless of actual direction he is moving in). So if the player is in the air and is not pressing A, this variable will be set to falling. When falling is set, the A button will be ignored until the player lands on solid ground again.

Then to prevent the player from jumping through ceilings, I'd have to set the falling flag as soon as the player hits his head in the ceiling, forcing the jump to be cancelled.

Top

 Post subject: Re: Learning Action Game BasicsPosted: Fri Sep 01, 2017 9:24 am

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 874
Location: cypress, texas
If your going to create a new variable: think about making it #\$ff when your character is standing somewhere, #\$00 when he/she is falling, and #01 when rising. That way you don't have to load another variable to find out if your player character is standing.

Code:
lda new_variable
bmi ++
beq +fall
; this would be code for rising or jumping
;followed by a branch (a jump) to ++
+fall

++

And if your player character is rising and you want to make him or her fall just dec new_variable. I was guided to do something like this! Want to pass it along.

Your logic seems well thought out. For me, I've not created many new variables because being guided to look at trace log files usually helps a solution be found that utilizes the variables that already exist (if not creating something new).

edit: did not change much; just removed one word

Last edited by unregistered on Fri Sep 01, 2017 10:25 am, edited 1 time in total.

Top

 Post subject: Re: Learning Action Game BasicsPosted: Fri Sep 01, 2017 9:56 am

Joined: Tue May 28, 2013 5:49 am
Posts: 972
Location: Sweden
Yeah I did it something like that. Instead of wasting RAM by creating a new variable I reused the variable I previously called "p1_ground". Its former meaning was 0 = mid-air, 1 = grounded, but I changed both its name to "p1_fall_state" and its meaning to: 0 = grounded, 1 = jumping (rising), 2 = falling. By setting it to 2 whenever either the jump button is released or a ceiling is hit, makes the jump (rising) to be cancelled, and the jump button is ignored until landing. It worked exactly like I wanted it to, and both the jetpack problem and the ceiling zipping problem are now solved.

But I didn't use INC or DEC to change fall state, I guess that might be a slight optimisation in certain situations.

Next I'll need to implement left and right wall collisions. I started a first attempt to implement it, but it didn't work very well at all. The player snaps in between metatiles and rightward movement on the ground broke. I recently got a new job, so I've been quite busy with that and didn't have any time to look into it at the moment. I'll be back when I do though.

Top

 Post subject: Re: Learning Action Game BasicsPosted: Fri Sep 01, 2017 10:32 am

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 874
Location: cypress, texas
Glad you got it to work! Using #\$ff, #\$00, and #\$01 is faster and smaller because you at least save a compare when checking to see if your player character is falling, I think...

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 3 of 3 [ 37 posts ] Go to page Previous  1, 2, 3

 All times are UTC - 7 hours

#### Who is online

Users browsing this forum: No registered users and 3 guests

 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot post attachments in this forum

Search for:
 Jump to:  Select a forum ------------------ NES / Famicom    NESdev    NESemdev    NES Graphics    NES Music    Homebrew Projects       2018 NESdev Competition       2017 NESdev Competition       2016 NESdev Competition       2014 NESdev Competition       2011 NESdev Competition    Newbie Help Center    NES Hardware and Flash Equipment       Reproduction    NESdev International       FCdev       NESdev China       NESdev Middle East Other    General Stuff    Membler Industries    Other Retro Dev       SNESdev       GBDev    Test Forum Site Issues    phpBB Issues    Web Issues    nesdevWiki