|
|
|||||||
| Home | Register | Downloads | FAQ | Members List | Calendar | Arcade | Mark Forums Read |
» Less advertising throughout
» Post and participate in discussions
» Network with other forum members
» Free private messaging
![]() |
|
|
Thread Tools | Display Modes |
|
|
#481 |
|
Registered User
![]() Join Date: Sep 2011
Location: Australia
Posts: 89
|
^Looks awesome Ref. As promised I have released I have released v0.01 of my chip16 compiler. Download link's here: http://code.google.com/p/chip16-dev-kit/ And here's the source code for Mega Man X 16 game: Code:
//Mega Man X 16 Compiler Demo
//Written by Prads
Image imgLogo = "logo.bin", 200, 175;
Image imgStand = "stand.bin", 40, 48;
Image imgShoot = "shoot.bin", 40, 48;
Image imgDash = "dash.bin", 60, 39;
Image imgFly = "fly.bin", 40, 58;
Image imgStormEagle = "stormEagle.bin", 40, 41;
Image imgBullet = "bullet.bin", 4, 4;
Image imgWin = "win.bin", 66, 100;
Image imgLose = "lose.bin", 88, 73;
Image imgMoon = "moon.bin", 100, 102;
ConstString title = "Mega Man X 16 by Prads";
ConstString pressStart = "Press Start";
ConstString win = "You Win";
ConstString lose = "You Lose";
void main() {
//Gamepad constants
const UP = 1; const DOWN = 2; const LEFT = 4; const RIGHT = 8;
const SELECT = 16; const START = 32; const A = 64; const B = 128;
//Flip constants
const FLIP_NONE = 0; const FLIP_VERTICAL = 1; const FLIP_HORIZONTAL = 2; const FLIP_BOTH = 3;
//Game scenes constants
const SCENE_START = 0; const SCENE_PLAY = 1; const SCENE_WIN = 2; const SCENE_LOSE = 3;
//Character glide control
const GLIDE_UP = 0; const GLIDE_DOWN = 1; const GLIDE_NONE = 2;
//Character Bullet constants
const BULLET_ACTIVE = 0; const BULLET_INACTIVE = 1;
var scene = SCENE_START; //Current game scene
const PLAYER_STAND = 0; const PLAYER_SHOOT = 1; const PLAYER_DASH = 2; const PLAYER_FLY = 3;
var playerX = 10; var playerY = 190; //x and y coordinates of player
var playerGlide = GLIDE_NONE; //player glide control
var playerSpriteType; //player sprite control
var playerBulletX; var playerBulletY; var playerBulletCtrl = BULLET_INACTIVE;
var enemyY = 190; //y coordinate of enemy
var enemyGlide = GLIDE_UP; //enemy glide control
var enemyBulletX; var enemyBulletY; var enemyBulletCtrl = BULLET_INACTIVE;
var enemyLife = 5;
//Game's main loop
while (1) {
ClearScreen;
//Game Scenes
if (scene == SCENE_START) { //Start Scene
Draw(imgLogo, 60, 10);
Print(title, 60, 200);
Print(pressStart, 115, 215);
if (GetController1 & START) {
scene = SCENE_PLAY;
}
} else if (scene == SCENE_PLAY) { //In Game Scene
//Draw Background Moon
Draw(imgMoon, 100, 50);
//Get gamepad buttons
if (playerGlide == GLIDE_NONE) {
playerSpriteType = PLAYER_STAND;
}
if (playerGlide == GLIDE_NONE) {
if(GetController1 & UP)) {
playerGlide = GLIDE_UP;
playerSpriteType = PLAYER_FLY;
}
} else if (playerGlide == GLIDE_UP) {
if (playerY > 100) {
playerY = playerY - 1;
} else {
playerGlide = GLIDE_DOWN;
}
} else {
if (playerY < 190) {
playerY = playerY + 1;
} else {
playerGlide = GLIDE_NONE;
}
}
if (GetController1 & A) {
if (playerBulletCtrl == BULLET_INACTIVE) {
playerBulletCtrl = BULLET_ACTIVE;
playerBulletX = playerX + 48;
playerBulletY = playerY + 20;
}
playerSpriteType = PLAYER_SHOOT;
} else if (GetController1 & LEFT) {
playerX = playerX - 1;
Flip(FLIP_HORIZONTAL);
playerSpriteType = PLAYER_DASH;
} else if (GetController1 & RIGHT) {
playerX = playerX + 1;
playerSpriteType = PLAYER_DASH;
}
//Draw Player Sprite
if (playerSpriteType == PLAYER_STAND) {
Draw(imgStand, playerX, playerY);
} else if (playerSpriteType == PLAYER_SHOOT) {
Draw(imgShoot, playerX, playerY);
} else if (playerSpriteType == PLAYER_DASH) {
Draw(imgDash, playerX, playerY);
} else {
Draw(imgFly, playerX, playerY);
}
//Draw Player Bullet
if (playerBulletCtrl == BULLET_ACTIVE) {
playerBulletX = playerBulletX + 3;
if (playerBulletX >= 320) {
playerBulletCtrl = BULLET_INACTIVE;
}
Draw(imgBullet, playerBulletX, playerBulletY);
}
//Enemy Glide
if (enemyGlide == GLIDE_UP) {
if (enemyY > 100) {
enemyY = enemyY - 1;
} else {
enemyGlide = GLIDE_DOWN;
}
} else {
if (enemyY < 190) {
enemyY = enemyY + 1;
} else {
enemyGlide = GLIDE_UP;
}
}
Flip(FLIP_NONE);
Draw(imgStormEagle, 280, enemyY); //draw enemy Sprite
//Draw Enemy Bullet
if (enemyBulletCtrl == BULLET_ACTIVE) {
enemyBulletX = enemyBulletX - 3;
if (enemyBulletX <= 0) {
enemyBulletCtrl = BULLET_INACTIVE;
}
Draw(imgBullet, enemyBulletX, enemyBulletY);
} else {
enemyBulletCtrl = Rand & 3;
if (enemyBulletCtrl == BULLET_ACTIVE) {
enemyBulletX = 280;
enemyBulletY = enemyY + 20;
}
}
//Player Bullet and Enemy Collision
if (playerBulletCtrl == BULLET_ACTIVE) {
if ((playerBulletX < 320) && (playerBulletX > 280) && (playerBulletY > enemyY) && (playerBulletY < enemyY + 40)) {
enemyLife = enemyLife - 1;
if (enemyLife == 0) {
scene = SCENE_WIN;
}
playerBulletCtrl = BULLET_INACTIVE;
}
}
//Enemy Bullet and Player Collision
if (enemyBulletCtrl == BULLET_ACTIVE) {
if ((enemyBulletX < playerX + 40) && (enemyBulletX > playerX) && (enemyBulletY > playerY) && (enemyBulletY < playerY + 40)) {
scene = SCENE_LOSE;
}
}
//Making sure this won't happen :P
if (playerX >= 240) {
scene = SCENE_LOSE;
}
} else if (scene == SCENE_WIN) { //Win Scene
Print(win, 130, 30);
Print(pressStart, 120, 40);
Draw(imgWin, 126, 55);
} else { //Lose Scene
Print(lose, 130, 30);
Print(pressStart, 120, 40);
Draw(imgLose, 126, 55);
}
//Reset variables and restart game
if ((scene == SCENE_WIN) || (scene == SCENE_LOSE)) {
if (GetController1 & START) {
playerX = 10; playerY = 190;
playerGlide = GLIDE_NONE;
playerBulletCtrl = BULLET_INACTIVE;
enemyY = 190;
enemyGlide = GLIDE_UP;
enemyBulletCtrl = BULLET_INACTIVE;
enemyLife = 5;
scene = SCENE_PLAY;
}
}
WaitScreenRefresh;
}
}
|
|
|
|
| Advertisement | [Remove Advertisement] | ||
|
|
|
#482 |
|
PCSX2 Coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2004
Location: Plymouth, UK
Posts: 10,037
|
nice one prads! that looks nice and easy to use! A little less painful than assembly thats for sure ;p
__________________
http://www.pcsx2.net Intel i7 920 @ 3.4Ghz, POV GTX 570 1.3Gb, 1.8Tb HD space, 6Gb OCZ Reaper PC3-14400 Triple Channel Dont PM me for help, use the forums, thats what its for! My Chip16 Emulator RefChip16 http://code.google.com/p/refchip16/
|
|
|
|
|
|
#483 |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
Looks good
|
|
|
|
|
|
#484 |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
I will hopefully get out my first chip16 demo in the next few days... It should be quite reminiscent of the good old days (think Amiga) LOL I have been wanting to get this demo done for a while now, but I had to figure out how to do a special sprite for it properly so some 'tricks' would work. I have now verified and created the sprite, I just have to write the code
|
|
|
|
|
|
#485 |
|
Sober coder
![]() ![]() ![]() Join Date: Aug 2010
Location: London, UK
Posts: 433
|
@refraction: Thanks for the heads up on the bug, will check it out tomorrow I guess. EDIT: Done. @Prads: Well done, this is pretty significant, I can't wait to try it!
__________________
Last edited by tykel; July 7th, 2012 at 15:41.. |
|
|
|
|
|
#486 |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
Hey guys, I'm having trouble with getting a sprite to display correctly... I have created a sprite which is 114 x 98 pixels (w x h) in size. This equates to 57 bytes * 98 bytes (in chip16 format) = 5586 bytes in total. I have tried code like this: Code:
importbin boing_spr.bin 0 5586 ball_sprite cBallSize equ $6239 ; 114 x 98 pixels sprite cBallX equ 104 ; starting x-location of ball cBallY equ 62 ; starting y-location of ball ;---------------------------------------------------------------- ; R0 = ball x ; R1 = ball y ;---------------------------------------------------------------- main: ; setup sprite spr cBallSize ldi R0, cBallX ldi R1, cBallY call draw_ball loop: jmp loop draw_ball: drw R0, R1, ball_sprite ret Any ideas? |
|
|
|
|
|
#487 | |
|
Sober coder
![]() ![]() ![]() Join Date: Aug 2010
Location: London, UK
Posts: 433
|
Quote:
The drawing code in the rom is fine, so the problem seems to lie in your drawing code. If we can compare what it should look like to what it actually looks like, we should be able to guess what is up.
__________________
|
|
|
|
|
|
|
#488 |
|
PCSX2 Coder
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jan 2004
Location: Plymouth, UK
Posts: 10,037
|
looks like youve got your height and width mixed up.. try doing SPR #7231
__________________
http://www.pcsx2.net Intel i7 920 @ 3.4Ghz, POV GTX 570 1.3Gb, 1.8Tb HD space, 6Gb OCZ Reaper PC3-14400 Triple Channel Dont PM me for help, use the forums, thats what its for! My Chip16 Emulator RefChip16 http://code.google.com/p/refchip16/
|
|
|
|
|
|
#489 |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
Nevermind, it was a combination of the wrong value in the spr opcode, and I had screwed up my sprite creating code! LOL It works now
Last edited by paul_nicholls; July 6th, 2012 at 23:16.. |
|
|
|
|
|
#490 |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
On this topic, I was wondering if the tchip16 assembler could be modified to accept extra spr input like this? Code:
spr w,h So this: Code:
spr 114,98 Code:
spr $6239 |
|
|
|
|
|
#491 |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
Or maybe even better (handy in lots of other ways), expression support in the assembler ![]() Then I could use this: spr w + (h << 8) |
|
|
|
|
|
#492 |
|
Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Feb 2006
Location: Croatia
Posts: 4,548
|
Paul, you are missing VBLNK in the sample above which may decrease framerate on some emulators. Edit: Hm, ignore that. I thought you were drawing sprite more than once.
__________________
Shendo's software blog Core i5 2400 3.1 Ghz | ASRock H67M | GTX460 768Mb | 8GB DDR3 1333 | 1500 Gb HDD Grundig VLC 7121 C (1080p) 32" | Razer DeathAdder | Logitech G110 | Windows 7 x64 Don't PM or ask me about VMP-MCR conversions. I will ignore you if you do. Last edited by ShendoXT; July 7th, 2012 at 12:58.. |
|
|
|
|
|
#493 | |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
Quote:
![]() That was just the bare-bones code anyway, the final thing has a VBLNK opcode in it ![]() Speaking of my code, I need to find a way to move RGB triplets from one position in a palette in the ROM to an adjacent part of the palette...effectively rotating the colors left or right in the palette. Unfortunately, I have looked at the store and load opcodes, and they all seem to deal with 16-bit values. This isn't going to do what I need since the 3 parts of a palette color don't fit evenly in one or two 16-bit words. Any ideas? |
|
|
|
|
|
|
#494 |
|
Moderator
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Feb 2006
Location: Croatia
Posts: 4,548
|
You could load 16 bit data and AND it with 0xFF to get a clean R, G and B values. Then you just store that data somewhere in the memory in the RGB order. If you want you can also have a 16 bit RG and B data. You would get RG with load and B with load AND 0XFF.
__________________
Shendo's software blog Core i5 2400 3.1 Ghz | ASRock H67M | GTX460 768Mb | 8GB DDR3 1333 | 1500 Gb HDD Grundig VLC 7121 C (1080p) 32" | Razer DeathAdder | Logitech G110 | Windows 7 x64 Don't PM or ask me about VMP-MCR conversions. I will ignore you if you do. |
|
|
|
|
|
#495 |
|
Sober coder
![]() ![]() ![]() Join Date: Aug 2010
Location: London, UK
Posts: 433
|
@Prads: I tried to compile a little test of mine and it compiled ok, but did not work. In the debugger I noticed the program started execution in the strings section of the ROM, rather than the code section (ie. PC was initially the first byte of 'Hello world!' :S)... Code so you can reproduce: Code:
ConstString strHello = "Hello world!"
void main() {
ClearScreen;
var ind;
ind = 0;
//while (ind < 10) {
Print(strHello, 5, 10*ind);
ind = ind + 1;
//}
while (1) {
WaitScreenRefresh;
}
}
__________________
|
|
|
|
|
|
#496 | |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
Quote:
Unless you are suggesting I copy the RG part (16-bit) then the GB (16-bit) from one color to another? That could work I guess even though it would copy 1 byte twice. |
|
|
|
|
|
|
#497 | |
|
Registered User
![]() Join Date: Sep 2011
Location: Australia
Posts: 89
|
Quote:
But also the Print doesn't take variables or expression as coordinate. Only const and literals. But I can make it take variables and expression in next version. Also feedbacks on what you want on next version would be helpful. I will try to add them. P.S. If someone wants to join in the development, they are welcome.
|
|
|
|
|
|
|
#498 |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
I've almost finished my first chip16 demo ![]() I want to add in some sound, and hopefully (but not essential), gravity... Stay tuned!!
|
|
|
|
|
|
#499 |
|
Registered User
![]() ![]() Join Date: Sep 2011
Location: Australia, Tasmania
Posts: 180
|
Here is my chip16 demo, inspired by the Amiga ![]() ![]() I have attached a zip file containing the source code & image binaries + .c16 file Enjoy! |
|
|
|
|
|
#500 |
|
Sober coder
![]() ![]() ![]() Join Date: Aug 2010
Location: London, UK
Posts: 433
|
@paul_nicholls: Wow. Great job mate, it looks brilliant. It showcases exactly how to use palette cycling to great effect
__________________
|
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|