add distinct camera
This commit is contained in:
parent
adccfcceb3
commit
6d09ea36be
|
@ -0,0 +1,3 @@
|
|||
build-fx/src/base.c.o: src/base.c include/base.h
|
||||
|
||||
include/base.h:
|
Binary file not shown.
|
@ -0,0 +1,26 @@
|
|||
build-fx/src/bullet.c.o: src/bullet.c include/bullets.h include/bonus.h \
|
||||
include/box.h include/constants.h include/mario.h include/box.h \
|
||||
include/tile.h include/camera.h include/base.h include/ennemi.h \
|
||||
include/score.h
|
||||
|
||||
include/bullets.h:
|
||||
|
||||
include/bonus.h:
|
||||
|
||||
include/box.h:
|
||||
|
||||
include/constants.h:
|
||||
|
||||
include/mario.h:
|
||||
|
||||
include/box.h:
|
||||
|
||||
include/tile.h:
|
||||
|
||||
include/camera.h:
|
||||
|
||||
include/base.h:
|
||||
|
||||
include/ennemi.h:
|
||||
|
||||
include/score.h:
|
Binary file not shown.
|
@ -0,0 +1,12 @@
|
|||
build-fx/src/camera.c.o: src/camera.c include/camera.h include/mario.h \
|
||||
include/box.h include/world.h include/base.h
|
||||
|
||||
include/camera.h:
|
||||
|
||||
include/mario.h:
|
||||
|
||||
include/box.h:
|
||||
|
||||
include/world.h:
|
||||
|
||||
include/base.h:
|
Binary file not shown.
|
@ -0,0 +1,12 @@
|
|||
#ifndef BASE_FUNCTIONS_H
|
||||
#define BASE_FUNCTIONS_H
|
||||
|
||||
// On va essayer de grapiller quelques octets d'executable avec ça
|
||||
|
||||
int max(const int x, const int y);
|
||||
|
||||
int min(const int x, const int y);
|
||||
|
||||
int sgn(const int x);
|
||||
|
||||
#endif
|
|
@ -0,0 +1,15 @@
|
|||
// v0.3
|
||||
#ifndef BULLETS_H
|
||||
#define BULLETS_H
|
||||
|
||||
// fire bullets
|
||||
// two maximum on the screen (static)
|
||||
// destroys ennemies, and is destroyed when it hits a wall
|
||||
|
||||
void bullet_throw();
|
||||
|
||||
void bullet_display();
|
||||
|
||||
void bullet_move();
|
||||
|
||||
#endif
|
|
@ -0,0 +1,20 @@
|
|||
#ifndef CAMERA_H
|
||||
#define CAMERA_H
|
||||
|
||||
// Top left corner coordinates
|
||||
int camera_x();
|
||||
int camera_y();
|
||||
|
||||
/* Auto track mario,
|
||||
The delay is custom:
|
||||
0 default
|
||||
1 to follow perfectly mario, no delay
|
||||
the higher the delay is, the longest time the camera takes to go to mario (recommended as inferior to 6)
|
||||
*/
|
||||
void camera_move(unsigned int delay);
|
||||
|
||||
void camera_reset(); // Reset camera to (0,0)
|
||||
|
||||
void camera_adjust(); // Set camera on mario -> useful when there is a pipe, for example
|
||||
|
||||
#endif
|
|
@ -0,0 +1,21 @@
|
|||
#include <base.h>
|
||||
|
||||
int max(const int x, const int y)
|
||||
{
|
||||
return (x<y?y:x);
|
||||
}
|
||||
|
||||
int min(const int x, const int y)
|
||||
{
|
||||
return (x>y?y:x);
|
||||
}
|
||||
|
||||
int sgn(const int x)
|
||||
{
|
||||
if (x>0)
|
||||
return 1;
|
||||
else if (x<0)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
#include <bullets.h>
|
||||
#include <bonus.h>
|
||||
#include <constants.h>
|
||||
#include <mario.h>
|
||||
#include <tile.h>
|
||||
#include <camera.h>
|
||||
#include <base.h>
|
||||
#include <ennemi.h>
|
||||
#include <score.h>
|
||||
/* Les balles ont les memes propriétés que les boulets et sont donc gérées ici */
|
||||
|
||||
static bonus_t bullets[2] =
|
||||
{
|
||||
{0, {0,0,TILE_W/2,TILE_H/2,0,0,0,1}, 0},
|
||||
{0, {0,0,TILE_W/2,TILE_H/2,0,0,0,1}, 0}
|
||||
};
|
||||
|
||||
void bullet_throw()
|
||||
{
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
if (bullets[i].type==0)
|
||||
{
|
||||
bullets[i].type=1;
|
||||
bullets[i].b.x=mario.p.x;
|
||||
bullets[i].b.y=mario.p.y+8;
|
||||
if (last_vx_sign==0)
|
||||
bullets[i].b.vx=-6;
|
||||
else
|
||||
bullets[i].b.vx=6;
|
||||
bullets[i].b.vy=0;
|
||||
bullets[i].p1=last_vx_sign;
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void bullet_display()
|
||||
{
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
if (bullets[i].type==1)
|
||||
draw_tile(bullets[i].b.x-camera_x(), bullets[i].b.y-camera_y(), &bullet, (1+sgn(bullets[i].b.vy))/2, 0);
|
||||
}
|
||||
}
|
||||
|
||||
void bullet_move()
|
||||
{
|
||||
for (int i=0; i<2; i++)
|
||||
{
|
||||
if (bullets[i].type==1)
|
||||
{
|
||||
box_jump(&bullets[i].b,4);
|
||||
box_move(&bullets[i].b);
|
||||
if (bullets[i].b.vx==0)
|
||||
bullets[i].type=0;
|
||||
if (bullets[i].b.y<0)
|
||||
bullets[i].type=0;
|
||||
if (bullets[i].b.x<=camera_x()-bullets[i].b.w || bullets[i].b.x>=camera_x()+127)
|
||||
bullets[i].type=0;
|
||||
for (int a=0; a<ennemis_global_size; a++)
|
||||
{
|
||||
ennemi_t* t=&ennemis_global[a];
|
||||
if (t->discovered && t->type!=NONE)
|
||||
{
|
||||
bool x_collide= (bullets[i].b.x<=t->b.x && t->b.x<bullets[i].b.x+bullets[i].b.w) || (bullets[i].b.x<=t->b.x+t->b.w-1 && t->b.x+t->b.w<bullets[i].b.x+bullets[i].b.w);
|
||||
bool y_collide= (bullets[i].b.y<=t->b.y && t->b.y<bullets[i].b.y+bullets[i].b.h) || (bullets[i].b.y<=t->b.y+t->b.h-1 && t->b.y+t->b.h<bullets[i].b.y+bullets[i].b.h);
|
||||
if (x_collide&& y_collide)
|
||||
{
|
||||
t->life=DEAD;
|
||||
bullets[i].type=0;
|
||||
score_add(KILL_ENNEMI);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,26 @@
|
|||
#include <camera.h>
|
||||
#include <mario.h>
|
||||
#include <world.h>
|
||||
#include <base.h>
|
||||
|
||||
static int y=0;
|
||||
|
||||
int camera_x() {return min(max(mario.p.x-40,0),w_current_x*8-128);}
|
||||
int camera_y() {return y;}
|
||||
|
||||
void camera_move(unsigned int delay)
|
||||
{
|
||||
if (!delay)
|
||||
delay=3; // on ajoute 1/3
|
||||
y+=(mario.p.y-y)/delay;
|
||||
}
|
||||
|
||||
void camera_adjust()
|
||||
{
|
||||
y=mario.p.y;
|
||||
}
|
||||
|
||||
void camera_reset()
|
||||
{
|
||||
y=0;
|
||||
}
|
Loading…
Reference in New Issue