- Comencem a treballar en les habitacions
This commit is contained in:
BIN
data/test.gif
BIN
data/test.gif
Binary file not shown.
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 2.9 KiB |
@@ -1,6 +1,7 @@
|
||||
#include "actor.h"
|
||||
#include "jdraw.h"
|
||||
#include "jinput.h"
|
||||
#include "room.h"
|
||||
|
||||
namespace actor
|
||||
{
|
||||
@@ -25,6 +26,7 @@ namespace actor
|
||||
act->size = s;
|
||||
act->bmp_rect = r;
|
||||
act->bmp_offset = o;
|
||||
act->anim_cycle = 0;
|
||||
act->below = act->above = nullptr;
|
||||
act->prev = act->next = nullptr;
|
||||
return act;
|
||||
@@ -100,32 +102,23 @@ namespace actor
|
||||
|
||||
if (act1->pos.x >= act2->pos.x+act2->size.x) { return true; }
|
||||
else if (act2->pos.x >= act1->pos.x+act1->size.x) { return false; }
|
||||
|
||||
if (act1->pos.y >= act2->pos.y+act2->size.y) { return true; }
|
||||
else if (act1->pos.y >= act2->pos.y+act2->size.y) { return true; }
|
||||
else if (act2->pos.y >= act1->pos.y+act1->size.y) { return false; }
|
||||
|
||||
if (act1->pos.z >= act2->pos.z+act2->size.z) { return true; }
|
||||
else if (act1->pos.z >= act2->pos.z+act2->size.z) { return true; }
|
||||
else if (act2->pos.z >= act1->pos.z+act1->size.z) { return false; }
|
||||
else { return false; }
|
||||
}
|
||||
|
||||
void reorder()
|
||||
{
|
||||
anim_frame=(anim_frame+1)%4;
|
||||
//dirty=first;
|
||||
//first=nullptr;
|
||||
while (dirty)
|
||||
{
|
||||
//const int z_index = dirty->pos.x + dirty->pos.y + dirty->pos.z;
|
||||
if (first)
|
||||
{
|
||||
actor_t *current = first;
|
||||
while (true)
|
||||
{
|
||||
//const int z_index2 = current->pos.x + current->pos.y + current->pos.z;
|
||||
//if ((dirty->pos.z < current->pos.z+current->size.z) && (current->pos.x+current->size.x+current->pos.y > dirty->pos.x+dirty->size.x+dirty->pos.y))
|
||||
|
||||
//if (current->pos.x+current->pos.y>dirty->pos.y+dirty->pos.x || current->pos.z+current->size.z>dirty->pos.z)
|
||||
//if (current->pos.x>dirty->pos.x+dirty->size.x || current->pos.y>dirty->pos.y+dirty->size.y || current->pos.z>dirty->pos.z+dirty->size.z)
|
||||
if (isInFront(current, dirty))
|
||||
{
|
||||
dirty->prev = current->prev;
|
||||
@@ -164,11 +157,14 @@ namespace actor
|
||||
|
||||
void updateUserInput(actor_t *act)
|
||||
{
|
||||
vec3_t min = room::getMin();
|
||||
vec3_t max = room::getMax();
|
||||
|
||||
bool moving = false;
|
||||
if (input::keyDown(SDL_SCANCODE_LEFT) && act->pos.x>0) { act->push |= PUSH_XN; act->orient=PUSH_XN; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_RIGHT) && act->pos.x<56) { act->push |= PUSH_XP; act->orient=PUSH_XP; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_UP) && act->pos.y>0) { act->push |= PUSH_YN; act->orient=PUSH_YN; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_DOWN) && act->pos.y<56) { act->push |= PUSH_YP; act->orient=PUSH_YP; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_LEFT) && act->pos.x>min.x) { act->push |= PUSH_XN; act->orient=PUSH_XN; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_RIGHT) && act->pos.x<max.x) { act->push |= PUSH_XP; act->orient=PUSH_XP; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_UP) && act->pos.y>min.y) { act->push |= PUSH_YN; act->orient=PUSH_YN; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_DOWN) && act->pos.y<max.y) { act->push |= PUSH_YP; act->orient=PUSH_YP; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_SPACE) && act->react_mask==0 && (act->pos.z==0 || act->below)) {
|
||||
act->react_mask=1;
|
||||
act->react_push=0;
|
||||
@@ -179,7 +175,7 @@ namespace actor
|
||||
}
|
||||
}
|
||||
if (input::keyDown(SDL_SCANCODE_Z) && act->pos.z>0) { act->push |= PUSH_ZN; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_A) && act->pos.z<56) { act->push |= PUSH_ZP; moving = true; }
|
||||
if (input::keyDown(SDL_SCANCODE_A) && act->pos.z<max.z) { act->push |= PUSH_ZP; moving = true; }
|
||||
|
||||
if (act->react_mask)
|
||||
{
|
||||
@@ -259,8 +255,11 @@ namespace actor
|
||||
|
||||
void updatePushable(actor_t *act)
|
||||
{
|
||||
vec3_t min = room::getMin();
|
||||
vec3_t max = room::getMax();
|
||||
|
||||
if (act->push & PUSH_ZP) {
|
||||
if (act->pos.z>=56)
|
||||
if (act->pos.z>=max.z)
|
||||
{
|
||||
if (act->flags & FLAG_MOVING) changeMoving(act);
|
||||
}
|
||||
@@ -281,7 +280,7 @@ namespace actor
|
||||
if (act->push & PUSH_XN) {
|
||||
act->pos.x--;
|
||||
actor::actor_t *other = actor::get_collision(act);
|
||||
if (act->pos.x<0 || other)
|
||||
if (act->pos.x<min.x || other)
|
||||
{
|
||||
if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_XN;
|
||||
act->pos.x++;
|
||||
@@ -306,7 +305,7 @@ namespace actor
|
||||
if (act->push & PUSH_XP) {
|
||||
act->pos.x++;
|
||||
actor::actor_t *other = actor::get_collision(act);
|
||||
if (act->pos.x>56 || other)
|
||||
if (act->pos.x>max.x || other)
|
||||
{
|
||||
if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_XP;
|
||||
act->pos.x--;
|
||||
@@ -331,7 +330,7 @@ namespace actor
|
||||
if (act->push & PUSH_YN) {
|
||||
act->pos.y--;
|
||||
actor::actor_t *other = actor::get_collision(act);
|
||||
if (act->pos.y<0 || other)
|
||||
if (act->pos.y<min.y || other)
|
||||
{
|
||||
if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_YN;
|
||||
act->pos.y++;
|
||||
@@ -356,7 +355,7 @@ namespace actor
|
||||
if (act->push & PUSH_YP) {
|
||||
act->pos.y++;
|
||||
actor::actor_t *other = actor::get_collision(act);
|
||||
if (act->pos.y>56 ||other)
|
||||
if (act->pos.y>max.y ||other)
|
||||
{
|
||||
if (other && other->flags & FLAG_PUSHABLE) other->push |= PUSH_YP;
|
||||
act->pos.y--;
|
||||
@@ -477,6 +476,7 @@ namespace actor
|
||||
//print(x+5,y,act->pos.x);
|
||||
//print(x+5,y+6,act->pos.y);
|
||||
//print(x+5,y+12,order);
|
||||
print(x+5,y,act->flags);
|
||||
|
||||
if (draw_all && act->next) draw(act->next);
|
||||
}
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include <SDL2/SDL.h>
|
||||
#include "misc.h"
|
||||
|
||||
#define FLAG_NONE 0
|
||||
#define FLAG_HERO 1
|
||||
@@ -30,11 +31,6 @@
|
||||
|
||||
namespace actor
|
||||
{
|
||||
struct vec3_t
|
||||
{
|
||||
int x, y, z;
|
||||
};
|
||||
|
||||
struct actor_t
|
||||
{
|
||||
SDL_Rect bmp_rect;
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
#include "jinput.h"
|
||||
#include <SDL2/SDL.h>
|
||||
#include "actor.h"
|
||||
#include "room.h"
|
||||
|
||||
draw::surface *surf;
|
||||
actor::actor_t *box;
|
||||
@@ -15,6 +16,8 @@ void game::init()
|
||||
draw::loadPalette("test.gif");
|
||||
game::setUpdateTicks(64);
|
||||
|
||||
room::load(0,3);
|
||||
|
||||
box = actor::create({16,16,0}, {8,8,4}, {64,0,32,24}, {0,24});
|
||||
box->flags = FLAG_MOVING;
|
||||
box->movement = MOV_Z;
|
||||
@@ -43,13 +46,7 @@ bool game::loop()
|
||||
actor::reorder();
|
||||
|
||||
draw::cls(8);
|
||||
for (int y=0;y<8;++y)
|
||||
{
|
||||
for (int x=0;x<8;++x)
|
||||
{
|
||||
draw::draw(148+x*16-y*16,76+x*8+y*8,32,15,0,1);
|
||||
}
|
||||
}
|
||||
room::draw();
|
||||
actor::draw(actor::getFirst());
|
||||
//draw::draw(148+sx*2-sy*2, 67+sx+sy,24,24,24,0);
|
||||
draw::render();
|
||||
|
||||
11
source/misc.h
Normal file
11
source/misc.h
Normal file
@@ -0,0 +1,11 @@
|
||||
#pragma once
|
||||
|
||||
struct vec2_t
|
||||
{
|
||||
int x, y;
|
||||
};
|
||||
|
||||
struct vec3_t
|
||||
{
|
||||
int x, y, z;
|
||||
};
|
||||
46
source/room.cpp
Normal file
46
source/room.cpp
Normal file
@@ -0,0 +1,46 @@
|
||||
#include "room.h"
|
||||
#include "jdraw.h"
|
||||
|
||||
namespace room
|
||||
{
|
||||
static vec3_t size = {8,8,8};
|
||||
static vec3_t tmin = {0,0,0};
|
||||
static vec3_t tmax = {7,7,7};
|
||||
static vec3_t min = {0,0,0};
|
||||
static vec3_t max = {56,56,56};
|
||||
|
||||
void load(int x, int y)
|
||||
{
|
||||
size = {(x+1)*2,(y+1)*2,3};
|
||||
tmin = {3-x,3-y,0};
|
||||
tmax = {4+x,4+y,3};
|
||||
min = {tmin.x*8,tmin.y*8,0};
|
||||
max = {tmax.x*8,tmax.y*8,24};
|
||||
}
|
||||
|
||||
void draw()
|
||||
{
|
||||
for (int y=tmin.y;y<=tmax.y;++y)
|
||||
{
|
||||
for (int x=tmin.x;x<=tmax.x;++x)
|
||||
{
|
||||
draw::draw(148+x*16-y*16,76+x*8+y*8,32,15,0,1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vec3_t getSize()
|
||||
{
|
||||
return size;
|
||||
}
|
||||
|
||||
vec3_t getMin()
|
||||
{
|
||||
return min;
|
||||
}
|
||||
|
||||
vec3_t getMax()
|
||||
{
|
||||
return max;
|
||||
}
|
||||
}
|
||||
12
source/room.h
Normal file
12
source/room.h
Normal file
@@ -0,0 +1,12 @@
|
||||
#pragma once
|
||||
#include "misc.h"
|
||||
|
||||
namespace room
|
||||
{
|
||||
void load(int x, int y);
|
||||
void draw();
|
||||
|
||||
vec3_t getSize();
|
||||
vec3_t getMin();
|
||||
vec3_t getMax();
|
||||
}
|
||||
Reference in New Issue
Block a user