uh cirno and poweritem -> item

This commit is contained in:
laochailan 2011-04-29 10:26:37 +02:00
parent 86f7f49988
commit c220f7b4ae
18 changed files with 224 additions and 189 deletions

View file

@ -4,7 +4,6 @@ cmake_minimum_required(VERSION 2.6)
add_subdirectory(src)
set(CMAKE_CFLAGS="--std=c99")
set(DATA_DIR "share/taisei")
install(DIRECTORY gfx DESTINATION ${DATA_DIR})

View file

@ -7,7 +7,7 @@ set(SRCs
projectile.c
enemy.c
animation.c
poweritem.c
item.c
list.c
font.c
audio.c

View file

@ -5,8 +5,8 @@
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
*/
#ifndef SLAVE_H
#define SLAVE_H
#ifndef ENEMY_H
#define ENEMY_H
#include "animation.h"
#include <complex.h>

View file

@ -7,6 +7,7 @@
#include "global.h"
#include <SDL/SDL.h>
#include <time.h>
#include "font.h"
Global global;
@ -16,6 +17,8 @@ void init_global() {
alGenSources(SNDSRC_COUNT, global.sndsrc);
srand(time(0));
load_resources();
init_fonts();
init_rtt();

View file

@ -12,7 +12,7 @@
#include "player.h"
#include "projectile.h"
#include "enemy.h"
#include "poweritem.h"
#include "item.h"
#include "audio.h"
#include "boss.h"
#include "laser.h"
@ -43,7 +43,7 @@ typedef struct {
Player plr;
Projectile *projs;
Enemy *enemies;
Poweritem *poweritems;
Item *items;
Laser *lasers;
int frames;

111
src/item.c Normal file
View file

@ -0,0 +1,111 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Code by Juergen Kieslich
*/
#include "item.h"
#include "global.h"
#include "list.h"
void create_item(complex pos, complex v, Type type) {
Item *i = create_element((void **)&global.items, sizeof(Item));
i->pos = pos;
i->pos0 = pos;
i->v = v;
i->birthtime = global.frames;
i->auto_collect = 0;
i->type = type;
}
void delete_item(Item *item) {
delete_element((void **)&global.items, item);
}
void draw_items() {
Item *p;
Texture *tex = NULL;
for(p = global.items; p; p = p->next){
switch(p->type){
case Power:
tex = get_tex("items/power");
break;
case Point:
tex = get_tex("items/point");
break;
case Life:
tex = get_tex("items/life");
break;
case Bomb:
tex = get_tex("items/bomb");
break;
default:
break;
}
draw_texture_p(creal(p->pos), cimag(p->pos), tex);
}
}
void delete_items() {
delete_all_elements((void **)&global.items, delete_element);
}
void move_item(Item *i) {
int t = global.frames - i->birthtime;
complex lim = 0 + 2I;
if(i->auto_collect)
i->pos -= 7*cexp(I*carg(i->pos - global.plr.pos));
else
i->pos = i->pos0 + log(t/5.0 + 1)*5*(i->v + lim) + lim*t;
}
void process_items() {
Item *item = global.items, *del = NULL;
int v;
while(item != NULL) {
if(cimag(global.plr.pos) < POINT_OF_COLLECT || cabs(global.plr.pos - item->pos) < 19 + global.plr.focus
|| global.frames - global.plr.recovery < 0)
item->auto_collect = 1;
move_item(item);
v = collision_item(item);
if(v == 1) {
switch(item->type) {
case Power:
global.plr.power += 0.1;
break;
case Point:
global.points += 100;
break;
case Life:
global.plr.lifes++;
break;
case Bomb:
global.plr.bombs++;
break;
}
play_sound("item_generic");
}
if(v == 1 || creal(item->pos) < -9 || creal(item->pos) > VIEWPORT_W + 9
|| cimag(item->pos) > VIEWPORT_H + 8 ) {
del = item;
item = item->next;
delete_item(del);
} else {
item = item->next;
}
}
}
int collision_item(Item *i) {
if(cabs(global.plr.pos - i->pos) < 5)
return 1;
return 0;
}

46
src/item.h Normal file
View file

@ -0,0 +1,46 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Code by: Juergen Kieslich
*/
#ifndef ITEM_H
#define ITEM_H
#include "texture.h"
#include <complex.h>
struct Item;
typedef enum {
Power,
Point,
Life,
Bomb
} Type;
typedef struct Item{
struct Item *next;
struct Item *prev;
long birthtime;
complex pos;
complex pos0;
int auto_collect;
Type type;
complex v;
} Item;
void create_item(complex pos, complex v, Type type);
void delete_item(Item *item);
void draw_items();
void delete_items();
int collision(Item *p);
void process_items();
#endif

View file

@ -51,7 +51,7 @@ void draw_laser_line(Laser *laser) {
glBindTexture(GL_TEXTURE_2D, get_tex("lasercurve")->gltex);
glColor4fv((float *)&laser->color);
glColor4fv((float *)laser->color);
glBegin(GL_QUADS);
glTexCoord2i(0,0);

View file

@ -12,7 +12,7 @@
#include "global.h"
#include "plrmodes.h"
void init_player(Player* plr, Character cha) {
void init_player(Player* plr, Character cha, ShotMode shot) {
plr->pos = VIEWPORT_W/2 + I*(VIEWPORT_H-20);
plr->focus = False;
@ -29,6 +29,7 @@ void init_player(Player* plr, Character cha) {
plr->recovery = 0;
plr->cha = cha;
plr->shot = shot;
switch(cha) {
case Youmu:
@ -89,22 +90,31 @@ void player_draw(Player* plr) {
void player_logic(Player* plr) {
process_enemies(&plr->slaves);
if(plr->fire && !(global.frames % 4)) {
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, -20I)->type = PlrProj;
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, -20I)->type = PlrProj;
if(plr->fire && plr->cha == Youmu) {
if(!(global.frames % 4)) {
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, -20I)->type = PlrProj;
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, -20I)->type = PlrProj;
if(plr->power >= 2) {
float a = 0.20;
if(plr->focus > 0) a = 0.06;
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, I*-20*cexp(-I*a))->type = PlrProj;
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, I*-20*cexp(I*a))->type = PlrProj;
if(plr->power >= 2) {
float a = 0.20;
if(plr->focus > 0) a = 0.06;
create_projectile("youmu", plr->pos - 10 - I*20, NULL, linear, I*-20*cexp(-I*a))->type = PlrProj;
create_projectile("youmu", plr->pos + 10 - I*20, NULL, linear, I*-20*cexp(I*a))->type = PlrProj;
}
}
float a = 1;
if(plr->focus > 0)
a = 0.2;
if(plr->shot == YoumuHoming && !(global.frames % 7))
create_projectile("hghost", plr->pos, NULL, youmu_homing, a*cexp(I*rand()))->type = PlrProj;
}
if(plr->focus < 0 || (plr->focus > 0 && plr->focus < 30))
plr->focus++;
if(plr->power >= 0 && plr->slaves == NULL)
if(plr->shot == YoumuOpposite && plr->slaves == NULL)
create_enemy(&plr->slaves, youmu_opposite_draw, youmu_opposite_logic, plr->pos, ENEMY_IMMUNE, plr, 0);
}
@ -128,8 +138,8 @@ void plr_death(Player *plr) {
if(plr->lifes-- == 0) {
game_over();
} else {
create_poweritem(plr->pos, 6-15*I, Power);
create_poweritem(plr->pos, -6-15*I, Power);
create_item(plr->pos, 6-15*I, Power);
create_item(plr->pos, -6-15*I, Power);
plr->pos = VIEWPORT_W/2 + VIEWPORT_H*I;
plr->recovery = -(global.frames + 200);

View file

@ -24,7 +24,8 @@ typedef enum {
} Character;
typedef enum {
YoumuOpposite
YoumuOpposite,
YoumuHoming
} ShotMode;
typedef struct {
@ -48,7 +49,7 @@ typedef struct {
Animation *ani;
} Player;
void init_player(Player*, Character cha);
void init_player(Player*, Character cha, ShotMode shot);
void player_draw(Player*);
void player_logic(Player*);

View file

@ -32,4 +32,24 @@ void youmu_opposite_logic(Enemy *e, int t) {
create_projectile("youmu", e->pos + plr->pos, NULL, linear, -20*cexp(I*e->args[1]))->type = PlrProj;
e->pos0 = e->pos + plr->pos;
}
void youmu_homing(complex *pos, complex *pos0, float *angle, int t, complex* a) { // a[0]: velocity
*angle = t/30.0;
complex tv = 0;
if(global.enemies != NULL)
tv = cexp(I*carg(global.enemies[0].pos - *pos));;
if(global.boss != NULL)
tv = cexp(I*carg(global.boss->pos - *pos));;
if(t > 150 || tv == 0)
tv = - ((rand()%3)-1)/2.0 - 0.5I;
complex s0 = 0;
*pos += a[0]*log(t + 1) + tv*t/15.0;
*pos0 = *pos;
}

View file

@ -13,4 +13,6 @@
void youmu_opposite_draw(Enemy *e, int t);
void youmu_opposite_logic(Enemy *e, int t);
void youmu_homing(complex *pos, complex *pos0, float *angle, int t, complex* a);
#endif

View file

@ -1,110 +0,0 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Code by Juergen Kieslich
*/
#include "poweritem.h"
#include "global.h"
#include "list.h"
void create_poweritem(complex pos, complex v, Type type) {
Poweritem *p = create_element((void **)&global.poweritems, sizeof(Poweritem));
p->pos = pos;
p->pos0 = pos;
p->v = v;
p->birthtime = global.frames;
p->auto_collect = 0;
p->type = type;
}
void delete_poweritem(Poweritem *poweritem) {
delete_element((void **)&global.poweritems, poweritem);
}
void draw_poweritems() {
Poweritem *p;
Texture *tex = NULL;
for(p = global.poweritems; p; p = p->next){
switch(p->type){
case Power:
tex = get_tex("items/power");
break;
case Point:
tex = get_tex("items/point");
break;
case Life:
tex = get_tex("items/life");
break;
case Bomb:
tex = get_tex("items/bomb");
break;
default:
break;
}
draw_texture_p(creal(p->pos), cimag(p->pos), tex);
}
}
void delete_poweritems() {
delete_all_elements((void **)&global.poweritems, delete_element);
}
void move_poweritem(Poweritem *p) {
int t = global.frames - p->birthtime;
complex lim = I*2;
if(p->auto_collect)
p->pos -= 7*cexp(I*carg(p->pos - global.plr.pos));
else
p->pos = p->pos0 + log(t/5.0 + 1)*5*(p->v + lim) + lim*t;
}
void process_poweritems() {
Poweritem *poweritem = global.poweritems, *del = NULL;
int v;
while(poweritem != NULL) {
if(cimag(global.plr.pos) < POINT_OF_COLLECT || cabs(global.plr.pos - poweritem->pos) < 19 + global.plr.focus
|| global.frames - global.plr.recovery < 0)
poweritem->auto_collect = 1;
move_poweritem(poweritem);
v = collision(poweritem);
if(v == 1) {
switch(poweritem->type) {
case Power:
global.plr.power += 0.1;
break;
case Point:
global.points += 100;
break;
case Life:
global.plr.lifes++;
break;
case Bomb:
global.plr.bombs++;
break;
}
play_sound("item_generic");
}
if(v == 1 || creal(poweritem->pos) < -9 || creal(poweritem->pos) > VIEWPORT_W + 9
|| cimag(poweritem->pos) > VIEWPORT_H + 8 ) {
del = poweritem;
poweritem = poweritem->next;
delete_poweritem(del);
} else {
poweritem = poweritem->next;
}
}
}
int collision(Poweritem *p) {
if(cabs(global.plr.pos - p->pos) < 5)
return 1;
return 0;
}

View file

@ -1,47 +0,0 @@
/*
* This software is licensed under the terms of the MIT-License
* See COPYING for further information.
* ---
* Copyright (C) 2011, Lukas Weber <laochailan@web.de>
* Code by: Juergen Kieslich
*/
#ifndef POWERITEM_H
#define POWERITEM_H
#include "texture.h"
#include <complex.h>
struct Poweritem;
typedef enum {
Power,
Point,
Life,
Bomb
} Type;
typedef struct Poweritem{
struct Poweritem *next;
struct Poweritem *prev;
long birthtime;
complex pos;
complex pos0;
int auto_collect;
Type type;
complex v;
} Poweritem;
void create_poweritem(complex pos, complex v, Type type);
void delete_poweritem(Poweritem *poweritem);
void draw_poweritems();
void delete_poweritems();
int collision(Poweritem *p);
void process_poweritems();
void simpleItem(int *y, int sy, float acc, long time, float *velo);
#endif

View file

@ -123,7 +123,7 @@ void draw_projectiles() {
void process_projectiles() {
Projectile *proj = global.projs, *del = NULL;
while(proj != NULL) {
proj->rule(&proj->pos, proj->pos0, &proj->angle, global.frames - proj->birthtime, proj->args);
proj->rule(&proj->pos, &proj->pos0, &proj->angle, global.frames - proj->birthtime, proj->args);
int v = collision_projectile(proj);
if(v == 1 && (global.frames - abs(global.plr.recovery)) >= 0)
@ -141,7 +141,7 @@ void process_projectiles() {
}
}
void linear(complex *pos, complex pos0, float *angle, int time, complex* a) { // sure is physics in here; a[0]: velocity
void linear(complex *pos, complex *pos0, float *angle, int time, complex* a) { // sure is physics in here; a[0]: velocity
*angle = carg(a[0]);
*pos = pos0 + a[0]*time;
*pos = *pos0 + a[0]*time;
}

View file

@ -21,7 +21,7 @@ typedef struct {
} Color;
struct Projectile;
typedef void (*ProjRule)(complex *pos, complex pos0, float *angle, int time, complex* args);
typedef void (*ProjRule)(complex *pos, complex *pos0, float *angle, int time, complex* args);
typedef struct Projectile {
struct Projectile *next;
@ -58,5 +58,5 @@ void draw_projectiles();
int collision_projectile(Projectile *p);
void process_projectiles();
void linear(complex *pos, complex pos0, float *angle, int time, complex* args);
void linear(complex *pos, complex *pos0, float *angle, int time, complex* args);
#endif

View file

@ -14,7 +14,7 @@
SDL_Event event;
void stage_start() {
init_player(&global.plr, Youmu);
init_player(&global.plr, Youmu, YoumuHoming);
}
void stage_input() {
@ -91,7 +91,7 @@ void stage_draw() {
draw_projectiles();
draw_enemies(global.enemies);
draw_poweritems();
draw_items();
draw_lasers();
if(global.boss)
@ -163,7 +163,7 @@ void stage_logic() {
process_enemies(&global.enemies);
process_projectiles();
process_poweritems();
process_items();
process_lasers();
if(global.boss) {
@ -187,7 +187,7 @@ void stage_logic() {
void stage_end() {
delete_projectiles();
delete_enemies(&global.enemies);
delete_poweritems();
delete_items();
delete_lasers();
global.frames = 0;
}

View file

@ -13,7 +13,7 @@
void simpleEnemy(Enemy *e, int t) {
if(t == EVENT_DEATH && global.plr.power < 6) {
create_poweritem(e->pos, 6-15*I, Power);
create_item(e->pos, 6*cexp(I*rand()), Power);
return;
} else if(t < 0) {
return;
@ -132,7 +132,7 @@ void cirno_test(Boss *c, int time) {
}
Boss *create_cirno() {
Boss* cirno = create_boss("Cirno", "fairy", VIEWPORT_W/2 + 30I);
Boss* cirno = create_boss("Cirno", "cirno", VIEWPORT_W/2 + 30I);
boss_add_attack(cirno, Normal, "Introduction", 10, 100, cirno_intro);
boss_add_attack(cirno, Spellcard, "Test Sign ~ Strongest Implementation", 10, 100, cirno_test);