Skip to content

Commit

Permalink
movimiento mas suave y fix de algunos niveles + fix de render de link
Browse files Browse the repository at this point in the history
  • Loading branch information
jvilarru committed Oct 10, 2013
1 parent 05e9dec commit bb84eeb
Show file tree
Hide file tree
Showing 12 changed files with 90 additions and 65 deletions.
7 changes: 4 additions & 3 deletions GLUTMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ void AppMouse(int button, int state, int x, int y)
}
void AppIdle()
{
if(glutGet(GLUT_ELAPSED_TIME) - inittime > (1./60.)*1000) {
inittime = glutGet(GLUT_ELAPSED_TIME);
int timeAct = glutGet(GLUT_ELAPSED_TIME);
if(timeAct - inittime > (1000./FPS)) {
inittime = timeAct;
if(!Game.Loop()) Game.Finalize();
}
}
Expand Down Expand Up @@ -103,7 +104,7 @@ void main(int argc, char** argv)
if (!Game.Init()){
int msgboxID = MessageBox(
NULL,
"Error in the init",
"Error in the pene",
"Error",
MB_OKCANCEL | MB_ICONERROR
);
Expand Down
4 changes: 3 additions & 1 deletion Globals.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@
#define IMG_BOSS 5

#define GAME_WIDTH (BLOCK_SIZE*SCENE_WIDTH+2*BLOCK_SIZE)
#define GAME_HEIGHT (BLOCK_SIZE*SCENE_HEIGHT+2*BLOCK_SIZE)
#define GAME_HEIGHT (BLOCK_SIZE*SCENE_HEIGHT+2*BLOCK_SIZE)

#define FPS 60
16 changes: 8 additions & 8 deletions cBicho.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ void cBicho::GetArea(cRect *rc)
void cBicho::DrawRect(int tex_id,float xo,float yo,float xf,float yf)
{
int screen_x,screen_y;

screen_x = x;
screen_y = y; /*+ (BLOCK_SIZE - TILE_SIZE)*/

Expand Down Expand Up @@ -211,13 +211,12 @@ void cBicho::Logic(int *map)
}
void cBicho::NextFrame(int max)
{
//delay++;
//if(delay == FRAME_DELAY)
//{
// seq++;
// seq%=max;
// delay = 0;
//}
delay++;
if(delay == FRAME_DELAY)
{
state = (state+1)%max;
delay = 0;
}
}
int cBicho::GetFrame()
{
Expand All @@ -238,6 +237,7 @@ int cBicho::GetDirection(){

void cBicho::SetDirection(int d){
direction = d;
seq = 0;
}

int cBicho::GetSpeed(){
Expand Down
10 changes: 5 additions & 5 deletions cBicho.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,21 @@
#include "cTexture.h"
#include "Globals.h"

#define FRAME_DELAY 8
#define STEP_LENGTH 2
#define FRAME_DELAY 4
#define STEP_LENGTH BLOCK_SIZE/FRAME_DELAY
#define JUMP_HEIGHT 96
#define JUMP_STEP 4

#define STATE_MOVE 1
#define STATE_IDLE 0
#define STATE_MOVE 1
#define STATE_ATTACK_1 2
#define STATE_ATTACK_2 3
#define STATE_SWORD 4

#define DIRECTION_UP 1
#define DIRECTION_DOWN 0
#define DIRECTION_RIGHT 3
#define DIRECTION_UP 1
#define DIRECTION_LEFT 2
#define DIRECTION_RIGHT 3

#define MONSTER_DOWN 0
#define MONSTER_RIGHT 1
Expand Down
37 changes: 9 additions & 28 deletions cGame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,8 +38,8 @@ bool cGame::Init()
Link.SetWidthHeight(BLOCK_SIZE,BLOCK_SIZE);
Link.SetBlock(PLAYER_START_CX,PLAYER_START_CY);
Link.SetState(STATE_IDLE);
Link.SetDirection(0);
Link.SetSpeed(BLOCK_SIZE/4); //MUST BE 32/x where x=y^2
Link.SetDirection(DIRECTION_UP);
Link.SetSpeed(STEP_LENGTH); //MUST BE 32/x where x=y^2
return res;
}

Expand Down Expand Up @@ -81,16 +81,9 @@ bool cGame::Process()
//Process Input
if(keys[27])
return false;
if(keys['e']) {
keys['e'] = false;
Link.SetState((Link.GetState()+1)%5);
Link.Draw(Data.GetID(IMG_PLAYER));
return true;
}
//TODO: comprovar que no salimos de los mapas que tenemos
if(keys['w']) {
keys['w'] = false;
/*if(Link.GetDirection() == DIRECTION_UP)Link.tirapalante(map);*/
if (Link.GetDirection()!=DIRECTION_UP)
Link.SetDirection(DIRECTION_UP);
res = Link.tirapalante(map);
if (!res) {
Expand All @@ -100,14 +93,11 @@ bool cGame::Process()
if (!Scene.LoadLevel(level))return false;
free(level);
}
if(Link.GetState() == STATE_IDLE) Link.SetState(STATE_MOVE);
else Link.SetState(STATE_IDLE);
Link.Draw(Data.GetID(IMG_PLAYER));
return true;
}
if(keys['a']) {
keys['a'] = false;
/*if(Link.GetDirection() == DIRECTION_LEFT)Link.tirapalante(map);*/
if (Link.GetDirection()!=DIRECTION_LEFT)
Link.SetDirection(DIRECTION_LEFT);
res = Link.tirapalante(map);
if (!res) {
Expand All @@ -117,14 +107,11 @@ bool cGame::Process()
if (!Scene.LoadLevel(level))return false;
free(level);
}
if(Link.GetState() == STATE_IDLE) Link.SetState(STATE_MOVE);
else Link.SetState(STATE_IDLE);
Link.Draw(Data.GetID(IMG_PLAYER));
return true;
}
if(keys['s']) {
keys['s'] = false;
/*if(Link.GetDirection() == DIRECTION_DOWN)Link.tirapalante(map);*/
if (Link.GetDirection()!=DIRECTION_DOWN)
Link.SetDirection(DIRECTION_DOWN);
res = Link.tirapalante(map);
if (!res) {
Expand All @@ -134,14 +121,11 @@ bool cGame::Process()
if (!Scene.LoadLevel(level))return false;
free(level);
}
if(Link.GetState() == STATE_IDLE) Link.SetState(STATE_MOVE);
else Link.SetState(STATE_IDLE);
Link.Draw(Data.GetID(IMG_PLAYER));
return true;
}
if(keys['d']) {
keys['d'] = false;
/*if(Link.GetDirection() == DIRECTION_RIGHT)Link.tirapalante(map);*/
if (Link.GetDirection()!=DIRECTION_RIGHT)
Link.SetDirection(DIRECTION_RIGHT);
res = Link.tirapalante(map);
if (!res) {
Expand All @@ -151,19 +135,14 @@ bool cGame::Process()
if (!Scene.LoadLevel(level))return false;
free(level);
}
if(Link.GetState() == STATE_IDLE) Link.SetState(STATE_MOVE);
else Link.SetState(STATE_IDLE);
Link.Draw(Data.GetID(IMG_PLAYER));
return true;
}

if(keys['j']) {
keys['j'] = false;
cPlayer linkSword = Link;
int xo, yo; Link.GetPosition(&xo, &yo);

Link.SetState(STATE_ATTACK_1);
Link.Draw(Data.GetID(IMG_PLAYER));
Render();
Sleep(50);
Link.SetState(STATE_ATTACK_2);
Expand Down Expand Up @@ -217,7 +196,9 @@ void cGame::Render()

Scene.Draw(Data.GetID(IMG_BLOCKS));
Link.Draw(Data.GetID(IMG_PLAYER));
if(LinkSword.isAlive()) LinkSword.Draw(Data.GetID(IMG_PLAYER));
if(LinkSword.isAlive()) {
LinkSword.Draw(Data.GetID(IMG_PLAYER));
}

for(i = 0; i < MAX_N_MONSTERS; ++i) {
//if(monsters[i].isAlive()) monsters[i].Draw(Data.GetID(IMG_MONSTER);
Expand Down
12 changes: 7 additions & 5 deletions cPlayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,12 @@ cPlayer::~cPlayer(){}
void cPlayer::Draw(int tex_id)
{
float xo,yo,despx,despy;
despx = 1.0/PLAYER_TEXTURE_WIDTH;
despy = 1.0/PLAYER_TEXTURE_HEIGHT;

xo = ((float) (GetDirection())) /PLAYER_TEXTURE_WIDTH;
yo = ((float) (GetState())) /PLAYER_TEXTURE_HEIGHT;
despx = (TILE_SIZE-1.0)/(TILE_SIZE*PLAYER_TEXTURE_WIDTH);
despy = (TILE_SIZE-1.0)/(TILE_SIZE*PLAYER_TEXTURE_HEIGHT);
float direction = GetDirection();
float state = GetState();
xo = direction /PLAYER_TEXTURE_WIDTH;
yo = state/PLAYER_TEXTURE_HEIGHT;

DrawRect(tex_id,xo,yo + despy,xo + despx,yo);
}
Expand Down Expand Up @@ -110,5 +111,6 @@ bool cPlayer::tirapalante(int* map){
break;
}
SetPosition(x,y);
NextFrame(2);
return true;
}
5 changes: 3 additions & 2 deletions cPlayer.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
#define PLAYER_START_CX 8
#define PLAYER_START_CY 5

#define PLAYER_TEXTURE_WIDTH 4;
#define PLAYER_TEXTURE_HEIGHT 5;
#define PLAYER_TEXTURE_WIDTH 4
#define PLAYER_TEXTURE_HEIGHT 5

#define STATE_LOOKUP 1
#define NUM_TRANS 8

class cPlayer: public cBicho
{
Expand Down
12 changes: 12 additions & 0 deletions levels/G7.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3

23 changes: 12 additions & 11 deletions levels/G8.txt
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
44,44,44,44,44,44,44,44,44,44,44,44,44,44,44,44
62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,
62,62,62,62,62,62,23,62,62,62,62,63,9,61,62,62,
9,9,3,3,3,3,3,3,3,9,9,9,9,9,62,62,
9,3,3,3,3,3,20,20,20,9,20,9,9,9,61,62,
9,3,3,3,3,3,3,3,20,9,20,9,9,9,9,61,
9,3,9,9,9,9,20,20,20,20,20,3,3,3,3,3,
9,3,3,3,3,3,20,3,20,3,9,3,3,3,3,43,
9,3,3,3,3,3,20,3,20,20,20,3,3,3,43,62,
9,9,3,3,3,3,3,3,3,3,3,3,3,3,62,62,
44,44,44,44,44,44,44,44,44,44,44,44,44,44,62,62,
62,62,62,62,62,62,62,62,62,62,62,62,62,62,62,62

12 changes: 12 additions & 0 deletions levels/H4.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3

5 changes: 3 additions & 2 deletions levels/H7.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3
3,3,3,3,3,3,3,3,3,3,3,3,3,3,127,128,
129,130,131,132,133,134,135,136,137,138,139,140,141,142,143,144

12 changes: 12 additions & 0 deletions levels/J2.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,
3,3,3,3,3,3,3,3,3,3,3,3,3,3,3,3

0 comments on commit bb84eeb

Please sign in to comment.