It is currently Sat Nov 18, 2017 1:34 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3
Author Message
PostPosted: Sun Aug 20, 2017 3:00 am 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 858
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
  adc temp+1
  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 15 times
Top
 Profile  
 
PostPosted: Mon Aug 21, 2017 9:06 am 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 803
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
 Profile  
 
PostPosted: Mon Aug 21, 2017 10:05 am 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 803
Location: cypress, texas
Pokun, when there is something like that that I don't get, I just use FCEUX's trace log. Iwould move the character under a ceiling, press the pause key, change the emulation to 1% speed, open the trace logger screen, click Log to File, click browse, input a file name, press Save, make sure everything is checked in the Log Options except for Symbolic trace and Log Cycles count and Log Instructions count, make sure nothing is checked in the Extra Log Options that work with the Code/Data Logger, press Start Logging, click on your game screen, press and hold the jump button, and press the pause key (the file will slowly start growing now). Let go of the jump button. Your character should have started jumping... click the Stop Logging button on the Trace Logger screen after your character jumps through the ceiling. Click the game window again and quickly press the pause key again. Now you can view the hex editor to see all of your variables after your character has jumped through the ceiling. Open the trace log text file you just created in notepad. Click Edit>Find.... If it was my game I would find "A:41 X:08" Down. That would jump to the line where the game recognized that I pressed the jump button. Then I would take note of the frame number, recorded on the far left, press ctrl+home, take note of the frame number at the top of the file. If the number at the top is smaller, I would click at the top, click the Find Next button again, scroll up until you reach the start of vblank, click at the beginning of the line, press shift+ctrl+home and press delete. Do something like that and your trace log files shouldn't be so big. :)

edit: using FCEUX 2.2.3


Top
 Profile  
 
PostPosted: Wed Aug 23, 2017 4:43 pm 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 858
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
 Profile  
 
PostPosted: Fri Sep 01, 2017 9:24 am 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 803
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! :mrgreen: 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
 Profile  
 
PostPosted: Fri Sep 01, 2017 9:56 am 
Offline

Joined: Tue May 28, 2013 5:49 am
Posts: 858
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
 Profile  
 
PostPosted: Fri Sep 01, 2017 10:32 am 
Offline
User avatar

Joined: Thu Apr 23, 2009 11:21 pm
Posts: 803
Location: cypress, texas
Glad you got it to work! :D 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
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 37 posts ]  Go to page Previous  1, 2, 3

All times are UTC - 7 hours


Who is online

Users browsing this forum: Bing [Bot] and 5 guests


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

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group