I may not be getting this completely becuase im tired, but I think i need more direction anyways. Right now I have a png, 256x32 WxL. Im trying to load this in memory, and display it as a sequence of frames. There are four frames in each direction. The first four, are the sections of walking left, and the second four are walking right. As you can probably tell, im trying to only display the section of frame where my character is located.
Code: Select all
#include <pspkernel.h>
#include <pspctrl.h>
#include <pspdebug.h>
#include <pspaudio.h>
#include <pspaudiolib.h>
#include <psppower.h>
#include <pspdisplay.h>
#include <pspgu.h>
#include <png.h>
#include <stdio.h>
#include "graphics.h"
#include "mp3player.h"
PSP_MODULE_INFO("Game Beta - v2 - Animation Seq.", 0, 1, 1);
#define printf pspDebugScreenPrintf
#define RGB(r,g,b) ((r)|((g)<<8)|((b)<<16))
#define MAX(X,Y) ((X)>(Y)?(X):(Y))
#define NEXT_FRAME 32
/* Exit callback */
int exit_callback(int arg1, int arg2, void *common){
sceKernelExitGame();
return 0;
}
/* Callback thread */
int CallbackThread(SceSize args, void *argp){
int cbid;
cbid = sceKernelCreateCallback("Exit Callback", exit_callback, NULL);
sceKernelRegisterExitCallback(cbid);
sceKernelSleepThreadCB();
return 0;
}
/* Sets up the callback thread and returns its threat id */
int SetupCallbacks(void){
int thid;
thid = sceKernelCreateThread("update_thread", CallbackThread, 0x11, 0xFA0, 0, 0);
if(thid >= 0){
sceKernelStartThread(thid, 0, 0);
}
return thid;
}
int main(){
// Set the power frequency
scePowerSetClockFrequency(333, 333, 166);
SetupCallbacks();
pspDebugScreenInit();
initGraphics();
pspAudioInit();
SceCtrlData pad;
char hero_buffer[200];
/* char enemy_buffer[200]; */
Image* ourHero;
/* Image* ourEnemy; */
MP3_Init(1);
MP3_Load("laser_1.mp3");
sprintf(hero_buffer, "walkseq.png");
ourHero = loadImage(hero_buffer);
/* animation variables */
int leftSeq[4]={32, 64, 96, 128};
int rightSeq[4]={160, 192, 224, 256};
int frame = 0;
int pos = rightSeq[frame];
/* sprintf(enemy_buffer, "enemyDude.png");
ourEnemy = loadImage(enemy_buffer); */
if(!ourHero){
//Image load failed
printf("Image load failed!\n");
}/*else if(!ourEnemy){
//Image load failed
printf("Image load failed!\n");
}*/else{
int hero_x = 0/*, enemy_x = 150*/;
int hero_y = 0/*, enemy_y = 0*/;
int bullet_x, bullet_y = 0;
sceDisplayWaitVblankStart();
while(1){
clearScreen(0);
fillScreenRect(RGB(255, 255, 255), 0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
blitAlphaImageToScreen(pos-32, 0, pos, 32, ourHero, hero_x, hero_y);
/* blitAlphaImageToScreen(0, 0, 32, 32, ourEnemy, enemy_x, enemy_y); */
sceCtrlReadBufferPositive(&pad, 1);
//meDude controls
if(pad.Buttons & PSP_CTRL_LEFT){
if(hero_x>0){hero_x--;}
pos = leftSeq[frame];
if(frame < 4){
frame++;
}else{
frame = 0;
}
}
if(pad.Buttons & PSP_CTRL_RIGHT){
if(hero_x<(480-32)){hero_x++;}
pos = rightSeq[frame];
if(frame < 4){
frame++;
}else{
frame = 0;
}
}
if(pad.Buttons & PSP_CTRL_UP){
if(hero_y>0){hero_y--;}
}
if(pad.Buttons & PSP_CTRL_DOWN){
if(hero_y<(272-32)){hero_y++;}
}
/* if(pad.Buttons & PSP_CTRL_SQUARE){
if(enemy_x>0){enemy_x--;}
} */
/* if(pad.Buttons & PSP_CTRL_CIRCLE){
if(enemy_x<(480-32)){enemy_x++;}
} */
/* if(pad.Buttons & PSP_CTRL_TRIANGLE){
if(enemy_y>0){enemy_y--;}
} */
if(pad.Buttons & PSP_CTRL_CROSS){
MP3_Play();
bullet_x = hero_x + 32;
bullet_y = hero_y + 16;
while(bullet_x < 480){
putPixelScreen(0, bullet_x, bullet_y);
bullet_x++;
flipScreen();
}
}
//if the MP3 finishes, stop it.
if(MP3_EndOfStream() == 1){
MP3_Stop();
}
sceDisplayWaitVblank();
flipScreen();
}
}
/* Stop MP3 & Free Memory */
/*MP3_Stop();*/
MP3_FreeTune();
sceKernelSleepThread();
return 0;
}