`
happysoul
  • 浏览: 398517 次
  • 性别: Icon_minigender_1
  • 来自: 天津
社区版块
存档分类
最新评论

CC65 开发FC/NES 游戏(四)方向键控制一个简单的精灵

阅读更多
因为缺少nes头信息的配置
所以cc65会有默认生成nes的配置
默认情况下:
使用水平镜像,田字格的左上和左下是镜像,我们看到的就是田字格的左上角显示部分



另外精灵不属于卷轴里固定显示的内容 右边的卷轴查看器不会看到精灵(也就是那个星号)

后面直接上附件:上下左右操作一个星号移动,以后再说把星号换成一个像游戏人物的图片,还有背景图

#include "conio.h"
#include "nes.h"
#include "stdio.h"
#include "stdlib.h"
#include "string.h"
// 加载手柄驱动
#include <joystick.h>  

typedef unsigned char u8;
#define address(add) (*(u8 *)(add))

// 定义读取手柄1
#define J1 joy_read (JOY_1);
#define J2 joy_read (JOY_2);

#define putSP(n,x,y,t,a) 	address(0x2003)=n*4;\
							address(0x2004)=y;\
							address(0x2004)=t;\
							address(0x2004)=a;\
							address(0x2004)=x

// 初始位置坐标
u8 x=100,y=60;
unsigned int p1;

// 1P 坐标
void read_joy1(){
	p1 = J1;
	if((p1 & 0x10) && 0x10){if(y>239){y=239;}else if(y==0){y=239;}else{y--;};}
	if((p1 & 0x20) && 0x20){++y;if(y>239)y=0;}
	if((p1 & 0x40) && 0x40){--x;}
	if((p1 & 0x80) && 0x80){++x;}
}

void main()
{
	// 清屏
	clrscr();
	// 初始化手柄
	joy_install (joy_static_stddrv);

	//这部分是开ppu显示屏幕,只在一个屏幕内显示
        //后面在研究透彻了这2个地址再回来补全注释
	address(0x2000) = 0x80;
	address(0x2001) = 0x1e;

	while(1){
		// 读取1P键位并处理坐标
		read_joy1();
		
		waitvsync();
		putSP(0,x,y,'*',0);
		gotoxy(0,0);
		cprintf("x:%-3d y:%-3d ",x,y);
	}
}




使用cc65的命令生成 nes文件的命令
引用
cl65 -t nes -o 简单精灵.nes 简单精灵.c

我们的源文件是 简单精灵.c
-t nes 就是告诉cc65 生成文件对应的平台是nes
  • 大小: 15 KB
0
0
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics