mirror of
https://git.planet-casio.com/Slyvtt/Collab_RPG.git
synced 2024-12-28 04:23:42 +01:00
The map displaying is now SUPER fast
This commit is contained in:
parent
9818d835be
commit
d3f1e55422
5 changed files with 94 additions and 98 deletions
|
@ -89,14 +89,12 @@ static void get_inputs( void )
|
|||
#endif
|
||||
|
||||
|
||||
void GameLogic( void )
|
||||
{
|
||||
void GameLogic(void) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
int main(void)
|
||||
{
|
||||
int main(void) {
|
||||
|
||||
#if USB_FEATURE==1
|
||||
usb_interface_t const *interfaces[] = {&usb_ff_bulk, NULL};
|
||||
|
|
127
src/map.c
127
src/map.c
|
@ -2,83 +2,80 @@
|
|||
|
||||
#include <gint/display.h>
|
||||
|
||||
#define T_HEIGHT 8
|
||||
#define T_WIDTH 8
|
||||
|
||||
void RenderMap(Player *player, Map *map_level) {
|
||||
/* for all Layer (2 in the current configuration: Background is layer 0 and
|
||||
* foreground is layer 1 ) */
|
||||
for (int u = 0; u < map_level->nblayers; u++){
|
||||
/* Draws a layer of the map on screen. */
|
||||
/* x and y will contain the position in the loop. */
|
||||
int x, y;
|
||||
/* The positions where we start drawing the tiles will be in tx and
|
||||
* ty. */
|
||||
int tx, ty;
|
||||
/* mx and my will contain how many pixels will be hidden on x and on
|
||||
* y. */
|
||||
int mx, my;
|
||||
/* dw and dh contain the amount of tiles that will be drawn on x and on
|
||||
* y. */
|
||||
int dw = DWIDTH/T_WIDTH+1, dh = DHEIGHT/T_HEIGHT+1;
|
||||
/* mw and mh will contain the height and the width of the map. */
|
||||
int mw = map_level->w*T_WIDTH, mh = map_level->h*T_HEIGHT;
|
||||
/* tile contains the tile to draw. */
|
||||
short int tile;
|
||||
/* The position where I start drawing */
|
||||
int sx, sy;
|
||||
/* Fix sx. */
|
||||
if(player->x<DWIDTH/2){
|
||||
/* If I can't center the player because I'm near the left border of
|
||||
* the map. */
|
||||
player->px = player->x;
|
||||
sx = 0;
|
||||
}else if(player->x+DWIDTH/2>mw){
|
||||
/* If I can't center the player because I'm near the right border of
|
||||
* the map. */
|
||||
sx = mw-DWIDTH;
|
||||
player->px = player->x-sx;
|
||||
}else{
|
||||
/* I can center the player. */
|
||||
player->px = DWIDTH/2;
|
||||
sx = player->x-player->px;
|
||||
}
|
||||
/* Fix sy. */
|
||||
if(player->y<DHEIGHT/2){
|
||||
/* If I can't center the player because I'm near the top border of
|
||||
* the map. */
|
||||
player->py = player->y;
|
||||
sy = 0;
|
||||
}else if(player->y+DHEIGHT/2>mh){
|
||||
/* If I can't center the player because I'm near the bottom border
|
||||
* of the map. */
|
||||
sy = mh-DHEIGHT;
|
||||
player->py = player->y-sy;
|
||||
}else{
|
||||
/* I can center the player. */
|
||||
player->py = DHEIGHT/2;
|
||||
sy = player->y-player->py;
|
||||
}
|
||||
tx = sx/T_WIDTH;
|
||||
ty = sy/T_HEIGHT;
|
||||
mx = sx-tx*T_WIDTH;
|
||||
my = sy-ty*T_HEIGHT;
|
||||
/* x and y will contain the position in the loop. */
|
||||
unsigned char x, y;
|
||||
/* The positions where we start drawing the tiles will be in tx and
|
||||
* ty. */
|
||||
unsigned short int tx, ty;
|
||||
/* mx and my will contain how many pixels will be hidden on x and on
|
||||
* y. */
|
||||
unsigned char mx, my;
|
||||
/* dw and dh contain the amount of tiles that will be drawn on x and on
|
||||
* y. */
|
||||
unsigned char dw = DWIDTH/T_WIDTH+1, dh = DHEIGHT/T_HEIGHT+1;
|
||||
/* mw and mh will contain the height and the width of the map. */
|
||||
unsigned short int mw = map_level->w*T_WIDTH, mh = map_level->h*T_HEIGHT;
|
||||
/* tile contains the tile to draw. */
|
||||
short int tile;
|
||||
/* The position where I start drawing */
|
||||
unsigned short int sx, sy;
|
||||
/* The position of the tile in the tileset. */
|
||||
unsigned short int xtile, ytile;
|
||||
/* The layer we're drawing */
|
||||
unsigned char l;
|
||||
/* Fix sx. */
|
||||
if(player->x<DWIDTH/2){
|
||||
/* If I can't center the player because I'm near the left border of
|
||||
* the map. */
|
||||
player->px = player->x;
|
||||
sx = 0;
|
||||
}else if(player->x+DWIDTH/2>mw){
|
||||
/* If I can't center the player because I'm near the right border of
|
||||
* the map. */
|
||||
sx = mw-DWIDTH;
|
||||
player->px = player->x-sx;
|
||||
}else{
|
||||
/* I can center the player. */
|
||||
player->px = DWIDTH/2;
|
||||
sx = player->x-player->px;
|
||||
}
|
||||
/* Fix sy. */
|
||||
if(player->y<DHEIGHT/2){
|
||||
/* If I can't center the player because I'm near the top border of
|
||||
* the map. */
|
||||
player->py = player->y;
|
||||
sy = 0;
|
||||
}else if(player->y+DHEIGHT/2>mh){
|
||||
/* If I can't center the player because I'm near the bottom border
|
||||
* of the map. */
|
||||
sy = mh-DHEIGHT;
|
||||
player->py = player->y-sy;
|
||||
}else{
|
||||
/* I can center the player. */
|
||||
player->py = DHEIGHT/2;
|
||||
sy = player->y-player->py;
|
||||
}
|
||||
tx = sx/T_WIDTH;
|
||||
ty = sy/T_HEIGHT;
|
||||
mx = sx-tx*T_WIDTH;
|
||||
my = sy-ty*T_HEIGHT;
|
||||
for (l = 0; l < map_level->nblayers; l++){
|
||||
/* Draw a layer of the map on screen. */
|
||||
for(y=0;y<dh;y++){
|
||||
for(x=0;x<dw;x++){
|
||||
/* I get the tile number if his position is inside the map. Then
|
||||
* I draw it. */
|
||||
if(tx+x>=0 && tx+x < map_level->w &&
|
||||
ty+y>=0 && ty+y < map_level->h){
|
||||
tile = map_level->layers[u][(y+ty) * map_level->w + tx+x];
|
||||
tile = map_level->layers[l][(y+ty) * map_level->w + tx+x];
|
||||
/* tile == -1 means nothing to be draw */
|
||||
if(tile >= 0){
|
||||
/* get x and y position in the tileset image */
|
||||
unsigned short int xtile = (tile %
|
||||
map_level->tileset_size) *
|
||||
T_WIDTH;
|
||||
unsigned short int ytile = (tile /
|
||||
map_level->tileset_size) *
|
||||
T_HEIGHT;
|
||||
xtile = (tile % map_level->tileset_size) * T_WIDTH;
|
||||
ytile = (tile / map_level->tileset_size) * T_HEIGHT;
|
||||
/* render */
|
||||
dsubimage(x*T_WIDTH-mx, y*T_HEIGHT-my,
|
||||
map_level->tileset, xtile, ytile, 8, 8,
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
#define T_HEIGHT 8
|
||||
#define T_WIDTH 8
|
||||
|
||||
#include <gint/display.h>
|
||||
|
||||
|
|
40
src/player.c
40
src/player.c
|
@ -2,39 +2,41 @@
|
|||
#include "map.h"
|
||||
#include <gint/display.h>
|
||||
|
||||
#define P_WIDTH 16
|
||||
#define P_HEIGHT 16
|
||||
#define P_WIDTH 8
|
||||
#define P_HEIGHT 8
|
||||
|
||||
extern Player MyPlayer;
|
||||
extern struct Map *map_level;
|
||||
extern Map *map_level;
|
||||
extern bopti_image_t demo_player_img;
|
||||
|
||||
void PlayerDraw( void )
|
||||
{
|
||||
void PlayerDraw(void) {
|
||||
dimage(MyPlayer.px-P_WIDTH/2, MyPlayer.py-P_HEIGHT/2, &demo_player_img);
|
||||
}
|
||||
|
||||
void PlayerLeft( void )
|
||||
{
|
||||
MyPlayer.x--;
|
||||
void PlayerLeft(void) {
|
||||
if(MyPlayer.x > 0){
|
||||
MyPlayer.x--;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerRight( void )
|
||||
{
|
||||
MyPlayer.x++;
|
||||
void PlayerRight(void) {
|
||||
if(MyPlayer.x < map_level->w * T_WIDTH){
|
||||
MyPlayer.x++;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerUp( void )
|
||||
{
|
||||
MyPlayer.y--;
|
||||
void PlayerUp(void) {
|
||||
if(MyPlayer.y > 0){
|
||||
MyPlayer.y--;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerDown( void )
|
||||
{
|
||||
MyPlayer.y++;
|
||||
void PlayerDown(void) {
|
||||
if(MyPlayer.y < map_level->h * T_HEIGHT){
|
||||
MyPlayer.y++;
|
||||
}
|
||||
}
|
||||
|
||||
void PlayerAction( void )
|
||||
{
|
||||
void PlayerAction(void) {
|
||||
|
||||
}
|
||||
|
|
17
src/player.h
17
src/player.h
|
@ -1,29 +1,26 @@
|
|||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
|
||||
/* Struct that define player parameters */
|
||||
typedef struct {
|
||||
unsigned short int x, y; /* The position of the player */
|
||||
short int px, py; /* The position of the player on screen */
|
||||
unsigned char px, py; /* The position of the player on screen */
|
||||
unsigned short int life; /* How many lives the player still has between 0
|
||||
* and 100. */
|
||||
} Player;
|
||||
|
||||
/* This function should be called after drawing the map ! */
|
||||
void PlayerDraw( void );
|
||||
void PlayerDraw(void);
|
||||
|
||||
void PlayerLeft( void );
|
||||
void PlayerLeft(void);
|
||||
|
||||
void PlayerRight( void );
|
||||
void PlayerRight(void);
|
||||
|
||||
void PlayerUp( void );
|
||||
void PlayerUp(void);
|
||||
|
||||
void PlayerDown( void );
|
||||
void PlayerDown(void);
|
||||
|
||||
void PlayerAction( void );
|
||||
void PlayerAction(void);
|
||||
|
||||
|
||||
#endif
|
||||
|
|
Loading…
Reference in a new issue