init uhhhh uhhhhhhhh uh uh uhu hhhhh

This commit is contained in:
t. boddy 2022-08-15 15:59:52 -04:00
parent 3d3de5b1e5
commit b7ebdb3c28
24 changed files with 1038 additions and 3 deletions

47
src/background.h Normal file
View file

@ -0,0 +1,47 @@
// bg
#define BG_I 512
#define BG_W GAME_W_T + 8
#define BG_H WIN_H_T
#define BG_SIZE 64
// draw
static void drawBg(){
for(u16 x = 0; x < BG_W; x++) for(u16 y = 0; y < BG_H; y++){
if(x % 8 == 0 && y % 8 == 0){
VDP_drawImageEx(BG_B, &bg1_1, TILE_ATTR_FULL(PAL2, 0, 0, 0, BG_I), x, y, 0, DMA);
}
}
}
// update
#define BG_SPEED_X -FIX16(0.2)
#define BG_SPEED_Y FIX16(0.1)
#define BG_SIZE_F FIX16(BG_SIZE)
Vect2D_f16 bgPos;
static void scrollBg(){
VDP_setHorizontalScroll(BG_B, fix16ToInt(bgPos.x));
VDP_setVerticalScroll(BG_B, fix16ToInt(bgPos.y));
bgPos.x = fix16Add(bgPos.x, BG_SPEED_X);
bgPos.y = fix16Add(bgPos.y, BG_SPEED_Y);
if(bgPos.x <= -BG_SIZE_F) bgPos.x = 0;
if(bgPos.y >= BG_SIZE_F) bgPos.y = 0;
}
// loop
void loadBg(){
drawBg();
}
void updateBg(){
// scrollBg();
}

76
src/chrome.h Normal file
View file

@ -0,0 +1,76 @@
// chrome
#define CHROME_I 32
static void loadChromeI(){
VDP_loadTileSet(frame1.tileset, CHROME_I, DMA);
VDP_loadTileSet(frame2.tileset, CHROME_I + 1, DMA);
VDP_loadTileSet(frame3.tileset, CHROME_I + 2, DMA);
}
static void drawFrame(){
VDP_fillTileMapRect(BG_A, TILE_ATTR_FULL(PAL1, 0, 0, 0, CHROME_I), 0, 0, WIN_W_T, GAME_Y_T - 1);
VDP_fillTileMapRect(BG_A, TILE_ATTR_FULL(PAL1, 0, 0, 0, CHROME_I + 1), 0, GAME_Y_T - 1, WIN_W_T, 1);
}
// score
#define SCORE_X 3
#define SCORE_Y 2
#define SCORE_LENGTH 6
u32 lastScore;
char scoreStr[SCORE_LENGTH];
static void loadScore(){
VDP_drawText("hi", 1, 1);
VDP_drawText("000000", SCORE_X, 1);
VDP_drawText("sc", 1, 2);
intToStr(score, scoreStr, SCORE_LENGTH);
VDP_drawText(scoreStr, SCORE_X, SCORE_Y);
}
static void updateScore(){
if(lastScore != score){
intToStr(score, scoreStr, SCORE_LENGTH);
VDP_drawText(scoreStr, SCORE_X, SCORE_Y);
lastScore = score;
}
score++;
}
// lives
#define LIVES_Y 4
static void loadLives(){
VDP_drawText("ENERGY 69", 1, LIVES_Y);
}
// dialogue
#define DIALOGUE_Y 24
static void loadDialogue(){
VDP_drawText("FLANDRE", 1, DIALOGUE_Y);
VDP_drawText("\"Are you morbid?", 1, DIALOGUE_Y + 1);
VDP_drawText("Are you morbid?\"", 1, DIALOGUE_Y + 2);
}
// loop
void loadChrome(){
// loadChromeI();
// drawFrame();
// loadScore();
// loadLives();
// loadDialogue();
}
void updateChrome(){
// updateScore();
}

21
src/controls.h Normal file
View file

@ -0,0 +1,21 @@
// controls
struct controls {
bool left, right, up, down, a, b, c, start;
};
struct controls ctrl;
void updateControls(u16 joy, u16 changed, u16 state){
if(joy == JOY_1){
if(changed){}
ctrl.left = (state & BUTTON_LEFT);
ctrl.right = (state & BUTTON_RIGHT);
ctrl.up = (state & BUTTON_UP);
ctrl.down = (state & BUTTON_DOWN);
ctrl.a = (state & BUTTON_A);
ctrl.b = (state & BUTTON_B);
ctrl.c = (state & BUTTON_C);
ctrl.start = (state & BUTTON_START);
}
}

25
src/global.h Normal file
View file

@ -0,0 +1,25 @@
// globals
#define WIN_W_T 32
#define WIN_H_T 28
#define WIN_W WIN_W_T * 8
#define WIN_H WIN_H_T * 8
#define GAME_W_T WIN_W_T
#define GAME_H_T WIN_H_T
#define GAME_W GAME_W_T * 8
#define GAME_H GAME_H_T * 8
#define GAME_X_T 0
#define GAME_Y_T 0
#define GAME_X 0
#define GAME_Y 0
#define CLOCK_LIMIT 32000
s16 clock;
u32 score;

51
src/main.c Normal file
View file

@ -0,0 +1,51 @@
// main
#include <genesis.h>
#include <resources.h>
#include "global.h"
#include "controls.h"
#include "background.h"
#include "tiles.h"
#include "player.h"
#include "chrome.h"
// game loop
static void loadInternals(){
JOY_init();
JOY_setEventHandler(&updateControls);
SPR_init(127, 0, 0);
VDP_setScreenWidth256();
VDP_setPalette(PAL1, tile1_1.palette -> data);
VDP_setPalette(PAL2, bg1_1.palette -> data);
VDP_loadFont(font.tileset, DMA);
VDP_setTextPalette(1);
}
static void loadGame(){
loadBg();
loadTiles();
loadChrome();
}
static void updateGame(){
updateBg();
updateChrome();
updateTiles();
clock++;
if(clock >= CLOCK_LIMIT) clock -= CLOCK_LIMIT;
}
// main loop
int main(){
loadInternals();
loadGame();
while(1){
updateGame();
SPR_update();
SYS_doVBlankProcess();
}
return(0);
}

32
src/player.h Normal file
View file

@ -0,0 +1,32 @@
// player
#define PLAYER_OFF FIX16(16)
#define PLAYER_INIT_X FIX16(32)
#define PLAYER_INIT_Y FIX16(32)
struct playerStruct {
Vect2D_f16 pos;
Sprite* image;
};
struct playerStruct player;
// spawn
static void spawnPlayer(){
player.pos.x = 0;
player.pos.y = 0;
player.image = SPR_addSprite(&reimu,
fix16ToInt(fix16Sub(player.pos.x, PLAYER_OFF)),
fix16ToInt(fix16Sub(player.pos.y, PLAYER_OFF)),
TILE_ATTR(PAL1, 0, 0, 0));
}
// loop
void loadPlayer(){}
void updatePlayer(){
spawnPlayer();
}

84
src/tiles.h Normal file
View file

@ -0,0 +1,84 @@
// tiles
#define TILE_I 128
#define TILE_W 128
#define TILE_COUNT 3072
u16 tileMap[TILE_COUNT];
u16 tileC;
static void loadTilesI(){
VDP_loadTileSet(tile1_1.tileset, TILE_I, DMA);
}
static void spawnTileRows(s16 y1, s16 y2, bool trig){
tileC = 0;
for(u16 y = 0; y < GAME_H_T; y++) for(u16 x = 0; x < TILE_W; x++){
if((y == y1 && tileMap[tileC - TILE_W] > 0 && random() % 4 < 3) || (y == y2 && tileMap[tileC + TILE_W] > 0 && trig)) tileMap[tileC] = 1;
tileC++;
}
}
static void spawnTiles(){
// initial ceiling and floor
tileC = 0;
for(u16 y = 0; y < GAME_H_T; y++) for(u16 x = 0; x < TILE_W; x++){
tileMap[tileC] = 0;
if(y == 0 || y == 23) tileMap[tileC] = 1;
tileC++;
}
// first go around
spawnTileRows(1, 22, random() % 4 < 3);
// second go around
spawnTileRows(2, 21, random() % 4 < 2);
// third go around
spawnTileRows(3, 20, random() % 4 < 1);
// draw small
tileC = 0;
for(u16 y = 0; y < GAME_H_T; y++) for(u16 x = 0; x < TILE_W; x++){
if(tileMap[tileC] > 0)
VDP_setTileMapXY(BG_A, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE_I), x, y + 4);
tileC++;
}
// if(tileMap[tileC] > 0 && x % 2 == 0 && y % 2 == 0) VDP_drawImageEx(BG_A, &tile1_2, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE_I + 1), x, y + 4, 0, DMA);
// if(x % 2 == 0 && tileC % 256 < 128 && tileMap[tileC] > 0){
// VDP_drawImageEx(BG_A, &tile1_2, TILE_ATTR_FULL(PAL1, 0, 0, 0, TILE_I + 1), x, 4, 0, DMA);
// }
// tileC++;
// }
// }
}
#define TILE_SPEED -1
#define TILE_LIMIT -TILE_W * 8
s16 tilePos[GAME_H_T];
static void scrollTiles(){
for(u16 y = 0; y < GAME_H_T; y++){
tilePos[y] += TILE_SPEED;
if(tilePos[y] <= TILE_LIMIT) tilePos[y] = 0;
}
VDP_setHorizontalScrollTile(BG_A, 4, tilePos, GAME_H_T, DMA);
}
// loop
void loadTiles(){
// loadTilesI();
// VDP_setScrollingMode(HSCROLL_TILE, VSCROLL_PLANE);
// spawnTiles();
}
void updateTiles(){
// scrollTiles();
}