Page 1 of 1

background changing

Posted: Sat Jun 18, 2005 6:40 pm
by Celius
Okay, I am making a small game that is basicly the same thing as pacman, and I have my title screen scroll down from the top. Then what I want is that when you press start, like it says to do so on the title screen, you can change the background to the map of the level, and start the game. I can't think of a way to do this. I hope it wasn't a bad idea to make the map of the level a .nam file. Whenever I write stuff saying do this when start is pressed, It does it anyway, even if start isn't pressed. and it doesn't even do the right stuff, which is changing the background. It just flashes the background for about a tenth of a second, and then stays at the title screen, and does it again after a second, and again and again. so yeah, how would you say change the background when start is pressed? thanks.

Posted: Sun Jun 19, 2005 12:26 am
by Quietust
One very handy way to do this is to have your game logic independent from your NMI routine.

Inside your NMI routine, perform 'vital' functions such as sprite DMA, palette updates and VRAM I/O, controller reading, and audio playback, and at the very end, increment some variable named 'nmicount'.

Elsewhere in your code, you will have a set of routines which start by waiting for nmicount to become nonzero (and then zeroing it afterwards), then perform some functions (checking input, executing game logic, queueing background/sprite updates, etc.), and then JMPing to some other routine based on the outcome (possibly the same one it's already in). Your very first routine in this group will be called 'Titlescreen' (or equivalent) and you will JMP to it at the end of your reset code (after NMIs are enabled, of course).

This has the advantage of being very easy to organize and expand and having less clutter in the 'important' routines (namely, your NMI and IRQ handlers).

I'm using this exact method in a game I'm making which is ALSO quite similar to Pac-Man but is still very much different. The player is a Drip™ of water, each level is a set of pipes, and the player must rust them while being chased by 4 enemies and avoiding hazards (electric coils between the pipes, projectiles shooting from the pipes) and collecting bonuses. The game itself is basically a port/remake of the Amiga game "Drip" by Art Skiles.

Posted: Thu Jun 23, 2005 9:36 pm
by Guest
Sorry, I still can't get things to work well. Well, I actually got my scrolling crap in my NMI routine, but for some reason, I can't get key readings right.
Here is my code to load the background:

Code: Select all

background:
	ldx #0
	lda #$20
	sta $2006
	stx $2006
	lda #low(titlescreen)
	sta adrlo
	lda #high(titlescreen)
	sta adrhi

	ldx #8
	ldy #0
loop:
	lda [adrlo], y
	sta $2007
	iny
	bne loop
	inc adrhi
	dex
	bne loop
Well my code for the keypresses at the moment only applies for the start key right now, cause I don't care about anything else at the moment.:

Code: Select all


        lda $4016
        do the same two more times
        lda $4016
        and #1
        bne StKey
        the rest are just lda $4016

StKey:
        lda LdStart
        sta SvStart

And this the embarassing attempt at changing the background:

Code: Select all

aaaa:
        lda #low(lev1)
        sta adrlo
        lda #high(lev1)
        sta adrhi

aaab:
        lda aaaa
        sta LdStart
        lda SvStart
        sta $2007

I think it's something wrong with my key presses, because nothing happens with that code. I'm sorry, I'm rambling on, and I'm sort of dumb feeling right now. So, whoever responds to this, thanks. :)

Posted: Thu Jun 23, 2005 9:42 pm
by Celius
Sorry, I forgot to log in before I posted the previous message. But just to let you know, I posted that thing above. :)

Posted: Fri Jun 24, 2005 12:41 pm
by Bregalad
Be sure that the screen *is* OFF when you're writing to the PPU via $2006; $2007. Uses Nintendolator tracing is a good way to ckeck if you're timing is okay or not.

Posted: Mon Jul 11, 2005 5:27 am
by xian106
I don't know why you do ,

Code: Select all

lda aaaa 
        sta LdStart 
        lda SvStart 
        sta $2007
Could you give me your source and all files needed,maybe I can help you to correct it.

Posted: Mon Jul 11, 2005 5:29 am
by xian106

Posted: Tue Jul 12, 2005 6:11 pm
by Celius
Oh yeah, I scrapped that code like a thousand years ago, so I don't have it any more. I think I would be pretty embarrased to look at it if I still had it. So , sorry, but thanks. :)