Ashbad wrote:
It's hard to trace this when we don't know what half the variables are used for, or what the surrounding code context is. Post some more, perhaps?
More code? Here's it all:
Code: #include "keyboard.hpp"
#include "keyboard_syscalls.h"
#include "display.h"
#include "color.h"
#include "stdlib.h"
#include "ZombieData.h"
void fillArea(int x, int y, int width, int height, int color) {
//only use lower two bytes of color
char* VRAM = (char*)0xA8000000;
VRAM += 2*(LCD_WIDTH_PX*y + x);
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
*(VRAM++) = (color&0x0000FF00)>>8;
*(VRAM++) = (color&0x000000FF);
}
VRAM += 2*(LCD_WIDTH_PX-width);
}
}
void CopySprite(const void* datar, int x, int y, int width, int height) {
if (x > 360 || x < 0){
return;
}
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
*(VRAM++) = *(data++);
}
VRAM += LCD_WIDTH_PX-width;
}
}
void CopySpriteMasked(const void*datar, int x, int y, int width, int height, int maskcolor) {
if (x > 360 || x < 0){
return;
}
color_t*data = (color_t*) datar;
color_t* VRAM = (color_t*)0xA8000000;
VRAM += LCD_WIDTH_PX*y + x;
for(int j=y; j<y+height; j++) {
for(int i=x; i<x+width; i++) {
if (*(data) != maskcolor) {
*(VRAM++) = *(data++);
} else { VRAM++; data++; }
}
VRAM += LCD_WIDTH_PX-width;
}
}
int PRGM_GetKey(){
unsigned char buffer[12];
PRGM_GetKey_OS( buffer );
return ( buffer[1] & 0x0F ) * 10 + ( ( buffer[2] & 0xF0 ) >> 4 );
}
void fill_scr(color_t color) {
unsigned int temp_color = (unsigned int)(color<<16) | color;
for(int i = 0; i < LCD_WIDTH_PX*LCD_HEIGHT_PX/2; i++) {
*((int*)0xA8000000+i) = temp_color;
}
}
int random(int lower, int upper) {
static int a = 123456789;
static int b = 362436069;
static int c = 521288629;
static int d = 88675123;
int t;
t = a ^ (a << 11);
a = b;
b = c;
c = d;
return (d = d ^ (d >> 19) ^ (t ^ (t >> 8)))%upper + lower;
}
int zombiespawn = 0;
int terrainx = 0;
int playerx = 185;
int playery = 153;
int leftright = 1;
int zombieleftright = 1;
int zombiex;
int zombiemover = 1;
int speedlimit = 0;
int level = 1;
int zombiehealth = 20;
int zombiey = 190;
int health = 200;
int zombie[20][5];
int mapdata[9][30] = {
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0},
{1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1}
};
int main() {
for(int h = 0; h < 20; h++){
zombie[h][0] = random(0,702);
zombie[h][1] = 190;
zombie[h][2] = 20;
zombie[h][3] = 1;
zombie[h][4] = 1;
}
while(1) {
int key = PRGM_GetKey();
if(key == KEY_PRGM_MENU) { GetKey(&key); }
fill_scr(0x306b);
for(int h = 0; h < 20; h++){
zombiespawn++;
speedlimit++;
if (speedlimit>=3 && zombie[h][1]==153){
zombie[h][0] = zombie[h][0] + zombie[h][3];
speedlimit = 0;
}
if ((zombie[h][0]+terrainx)==playerx){
zombie[h][4] = 0;
health-=2;
}
if(zombie[h][4] == 0){
CopySpriteMasked(ZombieRight, zombie[h][0]+terrainx, zombie[h][1], 18, 39, 0xf000);
}
if(zombie[h][4] == 1){
CopySpriteMasked(ZombieLeft, zombie[h][0]+terrainx, zombie[h][1], 18, 39, 0xf000);
}
if (playerx - (zombie[h][0]+terrainx) > 0){
zombie[h][3] = 1;
zombie[h][4] = 1;
}
if (playerx - (zombie[h][0]+terrainx) < 0){
zombie[h][3] = -1;
zombie[h][4] = 0;
}
if(zombiespawn == 5){
if (zombie[h][1] > 153){
for(int yminus = 0; yminus < 39; yminus++){
zombie[h][1]--;
Bdisp_PutDisp_DD;
Bdisp_AllCr_VRAM();
}
}
zombiespawn = 0;
}
}
for(int i = 0; i < 9; i++){
for(int j = 0; j < 30; j++){
if(mapdata[i][j] == 1){
CopySprite(Terrain1, j*24+terrainx, i*24, 24, 24);
}
}
}
if (leftright == 0){
CopySpriteMasked(PlayerLeft, playerx, playery, 14, 39, 0xf000);
}
if (leftright == 1){
CopySpriteMasked(PlayerRight, playerx, playery, 14, 39, 0xf000);
}
if (key==KEY_PRGM_LEFT){
terrainx = terrainx + 1;
leftright = 1;
}
if (key==KEY_PRGM_RIGHT){
terrainx = terrainx - 1;
leftright = 0;
}
fillArea(92, 5, health, 15, COLOR_RED);
Bdisp_PutDisp_DD();
Bdisp_AllCr_VRAM();
}
return 0;
}