(20111215) 12:00

This commit is contained in:
2011-12-15 12:00:00 +01:00
parent a80dda1a85
commit 0855d72749
38 changed files with 875 additions and 202 deletions

219
main.c
View File

@@ -1,114 +1,45 @@
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "GameLib.h"
#define MAP_ANCHO 11
#define MAP_ALTO 9
DrawImg tiles[20];
int mapa[MAP_ANCHO][MAP_ALTO];
// Dibujar el mapa
void DrawMapa(){
int x;
int y;
int value;
// dibujar el entorno
for(x=0;x<MAP_ANCHO-1;x++){
for(y=0;y<MAP_ALTO-1;y++){
value = mapa[x ][y ] * 8;
value += mapa[x+1][y ] * 4;
value += mapa[x ][y+1] * 2;
value += mapa[x+1][y+1] * 1;
Draw_DrawImg(tiles[value], x*64, y*64);
}
}
}
// Crear un mapa aleatorio
int CrearMapa(){
int x;
int y;
double rnd;
for(x=0;x<MAP_ANCHO;x++){
for(y=0;y<MAP_ALTO;y++){
rnd=rand();
rnd=rnd/RAND_MAX;
if(rnd>0.7){
mapa[x][y]=0;
}else{
mapa[x][y]=1;
}
}
}
return 0;
}
DrawFnt font;
DrawFnt fonts;
DrawImg bisho;
float xacel,yacel;
int xpos=0,ypos=0;
DrawFnt font_shad;
DrawImg img_bisho;
DrawImg img_bisho2;
DrawImg img_bloque;
AudioSnd coin;
int t_start,t_end;
int frames=0;
int ProcGame(){
int i;
//Draw_Clean(0,0,0);
DrawMapa();
if(Input_GetKey(InputKey_Up) && yacel>-10){
yacel-=2;
}
if(Input_GetKey(InputKey_Down) && yacel<10){
yacel+=2;
}
if(Input_GetKey(InputKey_Left) && xacel>-10){
xacel-=2;
}
if(Input_GetKey(InputKey_Right) && xacel<10){
xacel+=2;
}
if(xacel!=0){
xpos+=xacel;
if(xacel>0){
xacel-=1;
}else{
xacel+=1;
}
}
if(yacel!=0){
ypos+=yacel;
if(yacel>0){
yacel-=1;
}else{
yacel+=1;
}
}
Draw_DrawImgCenter(bisho,xpos,ypos);
Draw_DrawText(fonts,"BISHO!",xpos-15,ypos-23);
Draw_DrawText(font ,"BISHO!",xpos-16,ypos-24);
Entity *bisho;
Entity *bisho2;
Entity *bloque;
void ProcGame(){
Draw_Clean(0,0,0);
}
void PostProcGame(){
if(Input_GetKey(InputKey_Action1)==InputKey_Pressed){
Audio_PlaySound(coin,1,1);
}
/*for(i=0;i<1000;i++){
Draw_DrawImgCenter(bisho,rand()%640,rand()%480);
}*/
Draw_DrawText(font_shad,"Hola Mundo!",11,11);
Draw_DrawText(font ,"Hola Mundo!",10,10);
Draw_DrawText(fonts,"Hola Mundo!",11,11);
Draw_DrawText(font ,"Hola Mundo!",10,10);
}
frames++;
void player_proc(Entity *e){
vec2 vel;
return(1);
if(Input_GetDir(vel)){
vec2_scale(vel,vel,2.0f);
Entity_AddVelLimit(e,vel,10.0f);
}
}
int main(int argc,char *argv[]){
@@ -117,46 +48,84 @@ int main(int argc,char *argv[]){
GameLib_Init(640,480,"Game",60);
tiles[0] = Draw_LoadImage("data/tile0000.bmp");
tiles[1] = Draw_LoadImage("data/tile0001.bmp");
tiles[2] = Draw_LoadImage("data/tile0010.bmp");
tiles[3] = Draw_LoadImage("data/tile0011.bmp");
tiles[4] = Draw_LoadImage("data/tile0100.bmp");
tiles[5] = Draw_LoadImage("data/tile0101.bmp");
tiles[6] = Draw_LoadImage("data/tile0110.bmp");
tiles[7] = Draw_LoadImage("data/tile0111.bmp");
tiles[8] = Draw_LoadImage("data/tile1000.bmp");
tiles[9] = Draw_LoadImage("data/tile1001.bmp");
tiles[10] = Draw_LoadImage("data/tile1010.bmp");
tiles[11] = Draw_LoadImage("data/tile1011.bmp");
tiles[12] = Draw_LoadImage("data/tile1100.bmp");
tiles[13] = Draw_LoadImage("data/tile1101.bmp");
tiles[14] = Draw_LoadImage("data/tile1110.bmp");
tiles[15] = Draw_LoadImage("data/tile1111.bmp");
font=Draw_DefaultFont(255,255,255,255);
fonts=Draw_DefaultFont(0,0,0,127);
font_shad=Draw_DefaultFont(0,0,0,127);
//bisho=Draw_LoadImage("data/bisho.bmp");
//Draw_ImgSetKeyCol(bisho,0,255,0);
//Draw_ImgSetAlpha(bisho,127);
img_bisho=Draw_LoadImage("data/bisho_alpha.bmp");
Draw_ImgSetAlpha(img_bisho,255);
Draw_SetOffset(img_bisho,-16,-16);
bisho=Draw_LoadImage("data/bisho_alpha.bmp");
Draw_ImgSetAlpha(bisho,255);
xpos=320;
ypos=240;
img_bisho2=Draw_LoadImage("data/bisho2_alpha.bmp");
Draw_ImgSetAlpha(img_bisho2,255);
Draw_SetOffset(img_bisho2,-16,-16);
img_bloque=Draw_LoadImage("data/bloque.bmp");
Draw_ImgSetAlpha(img_bloque,255);
Draw_SetOffset(img_bloque,-16,-16);
coin=Audio_LoadSound("data/coin.wav");
CrearMapa();
bisho=Entity_New();
bisho->radius=16.0f;
bisho->img=img_bisho;
bisho->proc=player_proc;
bisho2=Entity_New();
bisho2->radius=16.0f;
bisho2->fric_static=0.1f;
bisho2->elast=0.0f;
bisho2->img=img_bisho2;
bloque=Entity_New();
bloque->mass=-1.0f;
bloque->radius=15.5f;
bloque->img=img_bloque;
int i;
Entity *e;
for(i=0;i<20;i++){
e=Entity_Copy(bloque);
vec2_set(e->pos,16+i*32,16);
GameLib_AddEntity(e);
}
for(i=0;i<20;i++){
e=Entity_Copy(bloque);
vec2_set(e->pos,16+i*32,464);
GameLib_AddEntity(e);
}
for(i=1;i<14;i++){
e=Entity_Copy(bloque);
vec2_set(e->pos,16,16+i*32);
GameLib_AddEntity(e);
}
for(i=1;i<14;i++){
e=Entity_Copy(bloque);
vec2_set(e->pos,624,16+i*32);
GameLib_AddEntity(e);
}
for(i=0;i<4;i++){
e=Entity_Copy(bloque);
vec2_set(e->pos,100,100+i*32);
GameLib_AddEntity(e);
}
for(i=0;i<4;i++){
e=Entity_Copy(bloque);
vec2_set(e->pos,164,100+i*32);
GameLib_AddEntity(e);
}
e=Entity_Copy(bisho2);
vec2_set(e->pos,132,100);
GameLib_AddEntity(e);
e=Entity_Copy(bisho);
vec2_set(e->pos,132,50);
GameLib_AddEntity(e);
GameLib_Loop(ProcGame,PostProcGame);
t_start=SDL_GetTicks();
Draw_Loop(ProcGame);
t_end=SDL_GetTicks();
printf("%d %d %.2f\n",t_end-t_start,frames,frames/((t_end-t_start)/1000.0f));
return(0);
}