diff options
Diffstat (limited to 'src/game/client/game_client.cpp')
| -rw-r--r-- | src/game/client/game_client.cpp | 1559 |
1 files changed, 276 insertions, 1283 deletions
diff --git a/src/game/client/game_client.cpp b/src/game/client/game_client.cpp index 2e95f187..2f05aa77 100644 --- a/src/game/client/game_client.cpp +++ b/src/game/client/game_client.cpp @@ -1,128 +1,46 @@ +#include <baselib/math.h> #include <stdlib.h> #include <stdio.h> #include <engine/config.h> #include "../game.h" #include "mapres_image.h" #include "mapres_tilemap.h" +#include "data.h" using namespace baselib; -static int texture_char_default = 0; -static int texture_game = 0; -static int texture_weapon = 0; -static int texture_sun = 0; -static int texture_particles = 0; +static data_container *data; -struct weapontexcell -{ - float x; - float y; - float w; - float h; -}; -struct renderparams -{ - float sizex; - float sizey; - float offsetx; - float offsety; -}; -int numcellsx = 32; -int numcellsy = 32; -renderparams weaponrenderparams[WEAPON_NUMWEAPONS]; -renderparams modifierrenderparams[WEAPON_NUMWEAPONS]; - -weapontexcell weaponprojtexcoord[WEAPON_NUMWEAPONS]; -weapontexcell weapontexcoord[WEAPON_NUMWEAPONS]; -weapontexcell weapontexcoordcursor[WEAPON_NUMWEAPONS]; - -weapontexcell poweruptexcoord[POWERUP_TYPE_NUMPOWERUPS]; - -weapontexcell modifiertexcoord[MODIFIER_NUMMODIFIERS]; -weapontexcell modifiertexcoordcursor[MODIFIER_NUMMODIFIERS]; - -int nummuzzletex[WEAPON_NUMWEAPONS]; -weapontexcell muzzletexcoord[WEAPON_NUMWEAPONS][3]; -renderparams muzzleparams[WEAPON_NUMWEAPONS]; - -#define NUMHADOKENS 6 -#define NUMSTARS 2 -#define NUMPARTICLES 9 -int particlesnumcellsx = 16; -int particlesnumcellsy = 16; -weapontexcell chaintexcoord; -weapontexcell chainheadtexcoord; -weapontexcell stars[NUMSTARS]; - -float lifemodifier[NUMPARTICLES]; -vec4 particlecolors[NUMPARTICLES]; -weapontexcell particlestexcoord[NUMPARTICLES]; +int charids[16] = {2,10,0,4,12,6,14,1,9,15,13,11,7,5,8,3}; -int charnumcellsx = 8; -int charnumcellsy = 32; -int charoffsety = 2; -weapontexcell body[2]; -weapontexcell leye; -weapontexcell reye; -weapontexcell feet[2]; - -int charids[16] = { 2,10,0,4,12,6,14,1,9,15,13,11,7,5,8,3 }; - -renderparams hadokenparams[6]; -weapontexcell hadoken[6]; - -float recoils[WEAPON_NUMWEAPONS] = { 10.0f, 10.0f, 10.0f, 10.0f }; - -static int font_texture = 0; static vec2 mouse_pos; - - static vec2 local_player_pos; static obj_player *local_player; -float frandom() -{ - return rand()/(float)(RAND_MAX); -} +inline float frandom() { return rand()/(float)(RAND_MAX); } -float sign(float f) +void snd_play_random(int setid, float vol, float pan) { - return f<0.0f?-1.0f:1.0f; -} - -// sound helpers -template<int N> -class sound_kit -{ -private: - int sounds[N]; - int last_id; -public: - sound_kit() : last_id(-1) { } + soundset *set = &data->sounds[setid]; - int& operator[](int id) { return sounds[id]; } - - inline void play_random(float vol = 1.0f, float pan = 0.0f); -}; - -template<> -inline void sound_kit<1>::play_random(float vol, float pan) -{ - snd_play(sounds[0], SND_PLAY_ONCE, vol, pan); -} - -template<int N> -inline void sound_kit<N>::play_random(float vol, float pan) -{ + if(!set->num_sounds) + return; + + if(set->num_sounds == 1) + { + snd_play(set->sounds[0].id, SND_PLAY_ONCE, vol, pan); + return; + } + + // play a random one int id; do { - id = rand() % N; - } while(id == last_id); - snd_play(sounds[id], SND_PLAY_ONCE, vol, pan); - last_id = id; + id = rand() % set->num_sounds; + } while(id == set->last); + snd_play(set->sounds[id].id, SND_PLAY_ONCE, vol, pan); + set->last = id; } - // sound volume tweak static const float stereo_separation = 0.01f; static const float stereo_separation_deadzone = 512.0f; @@ -133,31 +51,6 @@ static const float volume_tee = 0.5f; static const float volume_hit = 0.5f; static const float volume_music = 0.8f; -// sounds -sound_kit<3> sound_gun_fire; -sound_kit<3> sound_shotty_fire; -sound_kit<3> sound_flump_launch; -sound_kit<3> sound_hammer_swing; -sound_kit<3> sound_ninja_attack; - -sound_kit<3> sound_flump_explode; -sound_kit<4> sound_ninja_hit; - -sound_kit<3> sound_weapon_switch; - -sound_kit<12> sound_pain_short; -sound_kit<2> sound_pain_long; - -sound_kit<4> sound_body_jump; -sound_kit<4> sound_body_land; -sound_kit<2> sound_body_splat; - -sound_kit<7> sound_spawn; -sound_kit<2> sound_tee_cry; - -sound_kit<1> sound_hook_loop; -sound_kit<3> sound_hook_attach; - void sound_vol_pan(const vec2& p, float *vol, float *pan) { vec2 player_to_ev = p - local_player_pos; @@ -181,56 +74,45 @@ void sound_vol_pan(const vec2& p, float *vol, float *pan) } } -// TODO: we should do something nicer then this -static void cell_select_ex(int cx, int cy, float x, float y, float w, float h) +enum { - gfx_quads_setsubset(x/(float)cx,y/(float)cy,(x+w)/(float)cx,(y+h)/(float)cy); -} + SPRITE_FLAG_FLIP_Y=1, +}; -/* -static void cell_select_ex_flip_x(int cx, int cy, float x, float y, float w, float h) -{ - gfx_quads_setsubset((x+w)/(float)cx,y/(float)cy,x /(float)cx,(y+h)/(float)cy); -}*/ +static float sprite_w_scale; +static float sprite_h_scale; -static void cell_select_ex_flip_y(int cx, int cy, float x, float y, float w, float h) +static void select_sprite(sprite *spr, int flags=0, int sx=0, int sy=0) { - gfx_quads_setsubset(x/(float)cx,(y+h)/(float)cy,(x+w)/(float)cx,y/(float)cy); + int x = spr->x+sx; + int y = spr->y+sy; + int w = spr->w; + int h = spr->h; + int cx = spr->set->gridx; + int cy = spr->set->gridy; + + float f = sqrtf(h*h + w*w); + sprite_w_scale = w/f; + sprite_h_scale = h/f; + + if(flags&SPRITE_FLAG_FLIP_Y) + gfx_quads_setsubset(x/(float)cx,(y+h)/(float)cy,(x+w)/(float)cx,y/(float)cy); + else + gfx_quads_setsubset(x/(float)cx,y/(float)cy,(x+w)/(float)cx,(y+h)/(float)cy); } -/* -static void cell_select(int x, int y, int w, int h) -{ - gfx_quads_setsubset(x/16.0f,y/16.0f,(x+w)/16.0f,(y+h)/16.0f); -}*/ -inline void cell_select_flip_x(int x, int y, int w, int h) +static void select_sprite(int id, int flags=0, int sx=0, int sy=0) { - gfx_quads_setsubset((x+w)/16.0f,y/16.0f,(x)/16.0f,(y+h)/16.0f); + if(id < 0 || id > data->num_sprites) + return; + select_sprite(&data->sprites[id], flags, sx, sy); } -inline void cell_select_flip_y(int x, int y, int w, int h) +static void draw_sprite(float x, float y, float size) { - gfx_quads_setsubset(x/16.0f,(y+h)/16.0f,(x+w)/16.0f,(y)/16.0f); + gfx_quads_draw(x, y, size*sprite_w_scale, size*sprite_h_scale); } -struct particle -{ - vec2 pos; - vec2 vel; - float life; - float max_life; - float size; - - float rot; - float rotspeed; - - float gravity; - float friction; - int iparticle; - - vec4 color; -}; - void move_point(vec2 *inout_pos, vec2 *inout_vel, float elasticity) { vec2 pos = *inout_pos; @@ -320,7 +202,7 @@ public: i->pos.x += ((float)rand()/(float)RAND_MAX) * 5.0f; i->amount = amount; i->life = 1.5f; - i->istar = rand() % NUMSTARS; + i->istar = rand()%2; i->vel = vec2(((float)rand()/(float)RAND_MAX) * 50.0f,-150.0f); i->startangle = (( (float)rand()/(float)RAND_MAX) - 1.0f) * 2.0f * pi; } @@ -336,7 +218,7 @@ public: lastupdate = time_get(); float delta = (float) (lastupdate - lasttime) / (float)time_freq(); - gfx_texture_set(texture_particles); + gfx_texture_set(data->images[IMAGE_PARTICLES].id); gfx_quads_begin(); for(int i = 0; i < num_items;) { @@ -351,21 +233,9 @@ public: gfx_quads_setcolor(1.0f,1.0f,1.0f, items[i].life / 1.5f); gfx_quads_setrotation(items[i].startangle + items[i].life * 2.0f); float size = 64.0f; - cell_select_ex(particlesnumcellsx,particlesnumcellsy, stars[items[i].istar].x,stars[items[i].istar].y, stars[items[i].istar].w, stars[items[i].istar].h); + const int stars[] = {SPRITE_STAR1, SPRITE_STAR2}; + select_sprite(stars[items[i].istar]); gfx_quads_draw(items[i].pos.x-size/2, items[i].pos.y-size/2, size, size); - /*char buf[32]; - if(items[i].amount < 0) - { - sprintf(buf, "%d", items[i].amount*-1); - } - else - { - sprintf(buf, "%d", items[i].amount); - } - float size = 42.0f; - if(items[i].life > 1.25f) - size += 42.0f * ((items[i].life - 1.25f) * 4); - gfx_quads_text(items[i].pos.x-size/2, items[i].pos.y, size, buf);*/ i++; } } @@ -374,202 +244,29 @@ public: }; -/*class texture_animator -{ -public: - - int texture; - int numframes; - float duration; - float* framereltime; - weapontexcell* params; - texture_animator() - { - texture = -1; - numframes = 0; - duration = 0; - framereltime = 0; - params = 0; - } - - ~texture_animator() - { - if (params) - mem_free(params); - if (framereltime) - mem_free(framereltime); - } - - void create_anim(int texture, int numframes, float duration) - { - framereltime = 0; - params = 0; - this->texture = texture; - this->numframes = numframes; - this->duration = duration; - if (numframes) - { - framereltime = (float*)mem_alloc(sizeof(float) * numframes,1); - params = (weapontexcell*)mem_alloc(sizeof(renderparams) * numframes,1); - float delta = 1.0f / (float)(numframes - 1); - for (int i = 0; i < numframes; i++) - { - framereltime[i] = delta * i; - } - } - } - - static void create_gunmuzzle(texture_animator& anim, int texture, float duration) - { - anim.create_anim(texture, 3, duration); - anim.params[0].x = 8; - anim.params[0].y = 4; - anim.params[0].w = 3; - anim.params[0].h = 2; - anim.params[1].x = 12; - anim.params[1].y = 4; - anim.params[1].w = 3; - anim.params[1].h = 2; - anim.params[2].x = 16; - anim.params[2].y = 4; - anim.params[2].w = 3; - anim.params[2].h = 2; - } - - static void create_shotgunmuzzle() - { - - } -};*/ - -class keyframe -{ -public: - vec2 pos; - float angle; - float relativetime; -}; - -class anim -{ -public: - keyframe* keyframes; - int numframes; - float duration; - anim() - { - numframes = 0; - keyframes = 0; - } - ~anim() - { - if (keyframes) - mem_free(keyframes); - } - - void create_anim(int numframes, float duration) - { - if (keyframes) - mem_free(keyframes); - - this->numframes = numframes; - this->duration = duration; - keyframes = (keyframe*)mem_alloc(sizeof(keyframe) * numframes,1); - float delta = 1.0f / (float) (numframes - 1); - for (int i = 0; i < numframes; i++) - { - keyframes[i].pos = vec2(0.0f,0.0f); - keyframes[i].angle = 0; - keyframes[i].relativetime = delta * (float)i; - } - } - - void getframes(float relativetime, keyframe*& frame1, keyframe*& frame2, float& blend) - { - for (int i = 1; i < numframes; i++) - { - if (keyframes[i-1].relativetime <= relativetime && keyframes[i].relativetime >= relativetime) - { - frame1 = &keyframes[i-1]; - frame2 = &keyframes[i]; - blend = (relativetime - frame1->relativetime) / (frame2->relativetime - frame1->relativetime); - } - } - } - - void evalanim(float time, vec2& pos, float& angle) - { - float reltime = max(0.0f, min(1.0f, time / duration)); - keyframe* frame1 = 0; - keyframe* frame2 = 0; - float blend = 0.0f; - getframes(reltime, frame1, frame2, blend); - - if (frame1 && frame2) - { - pos = mix(frame1->pos, frame2->pos, blend); - angle = LERP(frame1->angle, frame2->angle, blend); - } - } - - static void setup_hammer(anim& hammeranim) - { - // straight up = -0.25 - // frame0 = standard pose time 0 - // frame1 = back a little time 0.3 - // frame2 = over head time 0.4 - // frame3 = on ground smashed time 0.5 - // frame4 = back to standard pose time 1.0 - hammeranim.create_anim(5, 1.0f); - // only angles... (for now...) - hammeranim.keyframes[0].angle = -0.35f * pi * 2.0f; - hammeranim.keyframes[1].angle = -0.4f * pi * 2.0f; - hammeranim.keyframes[1].relativetime = 0.3f; - hammeranim.keyframes[2].angle = -0.25f; - hammeranim.keyframes[2].relativetime = 0.4f; - hammeranim.keyframes[3].angle = 0.0f * pi * 2.0f; - hammeranim.keyframes[3].relativetime = 0.5f; - hammeranim.keyframes[4].angle = -0.35f * pi * 2.0f; - hammeranim.keyframes[4].relativetime = 1.0f; - } - - static void setup_ninja(anim& ninjanim) - { - // (straight up = -0.25) - // frame0 = standard pose straight back time 0.0 - // frame1 = overhead attack frame 1 time 0.1 - // frame2 = attack end frame time 0.15 - // frame3 = attack hold frame (a bit up) time 0.4 - // frame4 = attack hold frame end time 0.7 - // frame5 = endframe time 1.0 - ninjanim.create_anim(6, 1.0f); - // only angles... (for now...) - ninjanim.keyframes[0].angle = -0.5f * pi * 2.0f; - - ninjanim.keyframes[1].angle = -0.3f * pi * 2.0f; - ninjanim.keyframes[1].relativetime = 0.1f; - - ninjanim.keyframes[2].angle = 0.1f * pi * 2.0f; - ninjanim.keyframes[2].relativetime = 0.15f; - - ninjanim.keyframes[3].angle = -0.05f * pi * 2.0f; - ninjanim.keyframes[3].relativetime = 0.42; - - ninjanim.keyframes[4].angle = -0.05f * pi * 2.0f; - ninjanim.keyframes[4].relativetime = 0.5f; - - ninjanim.keyframes[5].angle = -0.5f * pi * 2.0f; - ninjanim.keyframes[5].relativetime = 1.0f; - } -}; - -static anim hammeranim; -static anim ninjaanim; static health_texts healthmods; class particle_system { public: + struct particle + { + vec2 pos; + vec2 vel; + float life; + float max_life; + float size; + + float rot; + float rotspeed; + + float gravity; + float friction; + int iparticle; + + vec4 color; + }; + enum { MAX_PARTICLES=1024, @@ -588,10 +285,10 @@ public: if (num_particles >= MAX_PARTICLES) return; - particles[num_particles].iparticle = rand() % NUMPARTICLES; + particles[num_particles].iparticle = rand() % data->num_particles; particles[num_particles].pos = pos; particles[num_particles].vel = vel; - particles[num_particles].life = life - lifemodifier[particles[num_particles].iparticle] * life; + particles[num_particles].life = life - (data->particles[particles[num_particles].iparticle].lifemod/100.0f) * life; particles[num_particles].size = size; particles[num_particles].max_life = life; particles[num_particles].gravity = gravity; @@ -626,23 +323,24 @@ public: void render() { gfx_blend_additive(); - gfx_texture_set(texture_particles); + gfx_texture_set(data->images[IMAGE_PARTICLES].id); gfx_quads_begin(); - //cell_select(4,1,1,1); - //cell_select(0,6,2,2); - //gfx_quads_setrotation(get_angle(vec2(proj->vx, proj->vy))); + for(int i = 0; i < num_particles; i++) { int type = particles[i].iparticle; - cell_select_ex(particlesnumcellsx,particlesnumcellsy,particlestexcoord[type].x, particlestexcoord[type].y, particlestexcoord[type].w, particlestexcoord[type].h); + select_sprite(data->particles[type].spr); float a = 1 - particles[i].life / particles[i].max_life; vec2 p = particles[i].pos; - //a *= length(particles[i].vel) * 0.01f; + gfx_quads_setrotation(particles[i].rot); - gfx_quads_setcolor(particlecolors[type].x,particlecolors[type].y,particlecolors[type].z,pow(a,0.75f)); - //gfx_quads_setcolor(particlecolors[type].x * 0.5,particlecolors[type].y * 0.5,particlecolors[type].z* 0.5,pow(a,0.75f)); - //gfx_quads_setcolor(particlecolors[type].x * 0.0,particlecolors[type].y * 0.0,particlecolors[type].z* 0.0,pow(a,0.75f)); - //gfx_quads_setcolor(0.64f*2,0.28f*2,0.16f*2,pow(a,0.75f)); + + gfx_quads_setcolor( + data->particles[type].color_r, + data->particles[type].color_g, + data->particles[type].color_b, + pow(a, 0.75f)); + gfx_quads_draw(p.x, p.y,particles[i].size,particles[i].size); } gfx_quads_end(); @@ -654,447 +352,17 @@ static particle_system temp_system; void modc_init() { - // load textures - texture_weapon = gfx_load_texture("data/tileset_weapons.png"); - texture_game = gfx_load_texture("data/game_main.png"); - texture_char_default = gfx_load_texture("data/char_teefault.png"); - texture_sun = gfx_load_texture("data/sun.png"); - texture_particles = gfx_load_texture("data/tileset_particles.png"); - font_texture = gfx_load_texture("data/debug_font.png"); - + // load the data container + data = load_data_container("data/client.dat"); // load sounds - sound_gun_fire[0] = snd_load_wav("data/audio/wp_gun_fire-01.wav"); - sound_gun_fire[0] = snd_load_wav("data/audio/wp_gun_fire-01.wav"); - sound_gun_fire[1] = snd_load_wav("data/audio/wp_gun_fire-02.wav"); - sound_shotty_fire[0] = snd_load_wav("data/audio/wp_shotty_fire-01.wav"); - sound_shotty_fire[1] = snd_load_wav("data/audio/wp_shotty_fire-02.wav"); - sound_shotty_fire[2] = snd_load_wav("data/audio/wp_shotty_fire-03.wav"); - sound_flump_launch[0] = snd_load_wav("data/audio/wp_flump_launch-01.wav"); - sound_flump_launch[1] = snd_load_wav("data/audio/wp_flump_launch-02.wav"); - sound_flump_launch[2] = snd_load_wav("data/audio/wp_flump_launch-03.wav"); - sound_hammer_swing[0] = snd_load_wav("data/audio/wp_hammer_swing-01.wav"); - sound_hammer_swing[1] = snd_load_wav("data/audio/wp_hammer_swing-02.wav"); - sound_hammer_swing[2] = snd_load_wav("data/audio/wp_hammer_swing-03.wav"); - sound_ninja_attack[0] = snd_load_wav("data/audio/wp_ninja_attack-01.wav"); - sound_ninja_attack[1] = snd_load_wav("data/audio/wp_ninja_attack-02.wav"); - sound_ninja_attack[2] = snd_load_wav("data/audio/wp_ninja_attack-03.wav"); - - sound_flump_explode[0] = snd_load_wav("data/audio/wp_flump_explo-01.wav"); - sound_flump_explode[1] = snd_load_wav("data/audio/wp_flump_explo-02.wav"); - sound_flump_explode[2] = snd_load_wav("data/audio/wp_flump_explo-03.wav"); - sound_ninja_hit[0] = snd_load_wav("data/audio/wp_ninja_hit-01.wav"); - sound_ninja_hit[1] = snd_load_wav("data/audio/wp_ninja_hit-02.wav"); - sound_ninja_hit[2] = snd_load_wav("data/audio/wp_ninja_hit-03.wav"); - sound_ninja_hit[3] = snd_load_wav("data/audio/wp_ninja_hit-04.wav"); - - sound_weapon_switch[0] = snd_load_wav("data/audio/wp_switch-01.wav"); - sound_weapon_switch[1] = snd_load_wav("data/audio/wp_switch-02.wav"); - sound_weapon_switch[2] = snd_load_wav("data/audio/wp_switch-03.wav"); - - sound_pain_short[0] = snd_load_wav("data/audio/vo_teefault_pain_short-01.wav"); - sound_pain_short[1] = snd_load_wav("data/audio/vo_teefault_pain_short-02.wav"); - sound_pain_short[2] = snd_load_wav("data/audio/vo_teefault_pain_short-03.wav"); - sound_pain_short[3] = snd_load_wav("data/audio/vo_teefault_pain_short-04.wav"); - sound_pain_short[4] = snd_load_wav("data/audio/vo_teefault_pain_short-05.wav"); - sound_pain_short[5] = snd_load_wav("data/audio/vo_teefault_pain_short-06.wav"); - sound_pain_short[6] = snd_load_wav("data/audio/vo_teefault_pain_short-07.wav"); - sound_pain_short[7] = snd_load_wav("data/audio/vo_teefault_pain_short-08.wav"); - sound_pain_short[8] = snd_load_wav("data/audio/vo_teefault_pain_short-09.wav"); - sound_pain_short[9] = snd_load_wav("data/audio/vo_teefault_pain_short-10.wav"); - sound_pain_short[10] = snd_load_wav("data/audio/vo_teefault_pain_short-11.wav"); - sound_pain_short[11] = snd_load_wav("data/audio/vo_teefault_pain_short-12.wav"); - - sound_pain_long[0] = snd_load_wav("data/audio/vo_teefault_pain_long-01.wav"); - sound_pain_long[1] = snd_load_wav("data/audio/vo_teefault_pain_long-02.wav"); - - sound_body_land[0] = snd_load_wav("data/audio/foley_land-01.wav"); - sound_body_land[1] = snd_load_wav("data/audio/foley_land-02.wav"); - sound_body_land[2] = snd_load_wav("data/audio/foley_land-03.wav"); - sound_body_land[3] = snd_load_wav("data/audio/foley_land-04.wav"); - sound_body_jump[0] = snd_load_wav("data/audio/foley_foot_left-01.wav"); - sound_body_jump[1] = snd_load_wav("data/audio/foley_foot_left-02.wav"); - sound_body_jump[2] = snd_load_wav("data/audio/foley_foot_left-03.wav"); - sound_body_jump[3] = snd_load_wav("data/audio/foley_foot_left-04.wav"); - sound_body_jump[4] = snd_load_wav("data/audio/foley_foot_right-01.wav"); - sound_body_jump[5] = snd_load_wav("data/audio/foley_foot_right-02.wav"); - sound_body_jump[6] = snd_load_wav("data/audio/foley_foot_right-03.wav"); - sound_body_jump[7] = snd_load_wav("data/audio/foley_foot_right-04.wav"); - - sound_body_splat[1] = snd_load_wav("data/audio/foley_body_splat-02.wav"); - sound_body_splat[2] = snd_load_wav("data/audio/foley_body_splat-03.wav"); - sound_body_splat[3] = snd_load_wav("data/audio/foley_body_splat-04.wav"); - - sound_spawn[0] = snd_load_wav("data/audio/vo_teefault_spawn-01.wav"); - sound_spawn[1] = snd_load_wav("data/audio/vo_teefault_spawn-02.wav"); - sound_spawn[2] = snd_load_wav("data/audio/vo_teefault_spawn-03.wav"); - sound_spawn[3] = snd_load_wav("data/audio/vo_teefault_spawn-04.wav"); - sound_spawn[4] = snd_load_wav("data/audio/vo_teefault_spawn-05.wav"); - sound_spawn[5] = snd_load_wav("data/audio/vo_teefault_spawn-06.wav"); - sound_spawn[6] = snd_load_wav("data/audio/vo_teefault_spawn-07.wav"); - - sound_tee_cry[0] = snd_load_wav("data/audio/vo_teefault_cry-01.wav"); - sound_tee_cry[1] = snd_load_wav("data/audio/vo_teefault_cry-02.wav"); - - //sound_hook_loop[0] = snd_load_wav("data/audio/hook_loop-01.wav"); - sound_hook_loop[0] = snd_load_wav("data/audio/hook_loop-02.wav"); - sound_hook_attach[0] = snd_load_wav("data/audio/hook_attach-01.wav"); - sound_hook_attach[1] = snd_load_wav("data/audio/hook_attach-02.wav"); - sound_hook_attach[2] = snd_load_wav("data/audio/hook_attach-03.wav"); - - poweruptexcoord[POWERUP_TYPE_HEALTH].x = 10; - poweruptexcoord[POWERUP_TYPE_HEALTH].y = 2; - poweruptexcoord[POWERUP_TYPE_HEALTH].w = 2; - poweruptexcoord[POWERUP_TYPE_HEALTH].h = 2; - - poweruptexcoord[POWERUP_TYPE_ARMOR].x = 12; - poweruptexcoord[POWERUP_TYPE_ARMOR].y = 2; - poweruptexcoord[POWERUP_TYPE_ARMOR].w = 2; - poweruptexcoord[POWERUP_TYPE_ARMOR].h = 2; - - poweruptexcoord[POWERUP_TYPE_WEAPON].x = 3; - poweruptexcoord[POWERUP_TYPE_WEAPON].y = 0; - poweruptexcoord[POWERUP_TYPE_WEAPON].w = 6; - poweruptexcoord[POWERUP_TYPE_WEAPON].h = 2; - - poweruptexcoord[POWERUP_TYPE_NINJA].x = 3; - poweruptexcoord[POWERUP_TYPE_NINJA].y = 10; - poweruptexcoord[POWERUP_TYPE_NINJA].w = 7; - poweruptexcoord[POWERUP_TYPE_NINJA].h = 2; - - poweruptexcoord[POWERUP_TYPE_TIMEFIELD].x = 3; - poweruptexcoord[POWERUP_TYPE_TIMEFIELD].y = 0; - poweruptexcoord[POWERUP_TYPE_TIMEFIELD].w = 6; - poweruptexcoord[POWERUP_TYPE_TIMEFIELD].h = 2; - - // Setup weapon cell coords - float sizemodifier = 1.0f; - weaponrenderparams[WEAPON_TYPE_GUN].sizex = 60.0f * sizemodifier; - weaponrenderparams[WEAPON_TYPE_GUN].sizey = 30.0f * sizemodifier; - weaponrenderparams[WEAPON_TYPE_GUN].offsetx = 32.0f; - weaponrenderparams[WEAPON_TYPE_GUN].offsety = 4.0f; - weapontexcoordcursor[WEAPON_TYPE_GUN].x = 0; - weapontexcoordcursor[WEAPON_TYPE_GUN].y = 4; - weapontexcoordcursor[WEAPON_TYPE_GUN].w = 2; - weapontexcoordcursor[WEAPON_TYPE_GUN].h = 2; - weapontexcoord[WEAPON_TYPE_GUN].x = 2; - weapontexcoord[WEAPON_TYPE_GUN].y = 4; - weapontexcoord[WEAPON_TYPE_GUN].w = 4; - weapontexcoord[WEAPON_TYPE_GUN].h = 2; - weaponprojtexcoord[WEAPON_TYPE_GUN].x = 6; - weaponprojtexcoord[WEAPON_TYPE_GUN].y = 4; - weaponprojtexcoord[WEAPON_TYPE_GUN].w = 2; - weaponprojtexcoord[WEAPON_TYPE_GUN].h = 2; - - nummuzzletex[WEAPON_TYPE_GUN] = 3; - muzzletexcoord[WEAPON_TYPE_GUN][0].x = 8; - muzzletexcoord[WEAPON_TYPE_GUN][0].y = 4; - muzzletexcoord[WEAPON_TYPE_GUN][0].w = 3; - muzzletexcoord[WEAPON_TYPE_GUN][0].h = 2; - muzzletexcoord[WEAPON_TYPE_GUN][1].x = 12; - muzzletexcoord[WEAPON_TYPE_GUN][1].y = 4; - muzzletexcoord[WEAPON_TYPE_GUN][1].w = 3; - muzzletexcoord[WEAPON_TYPE_GUN][1].h = 2; - muzzletexcoord[WEAPON_TYPE_GUN][2].x = 16; - muzzletexcoord[WEAPON_TYPE_GUN][2].y = 4; - muzzletexcoord[WEAPON_TYPE_GUN][2].w = 3; - muzzletexcoord[WEAPON_TYPE_GUN][2].h = 2; - - muzzleparams[WEAPON_TYPE_GUN].sizex = 60.0f * sizemodifier; - muzzleparams[WEAPON_TYPE_GUN].sizey = 40.0f * sizemodifier; - muzzleparams[WEAPON_TYPE_GUN].offsetx = 50.0f * sizemodifier; - muzzleparams[WEAPON_TYPE_GUN].offsety = 6.0f * sizemodifier; - - sizemodifier = 1.3f; - weaponrenderparams[WEAPON_TYPE_ROCKET].sizex = 70.0f * sizemodifier; - weaponrenderparams[WEAPON_TYPE_ROCKET].sizey = 20.0f * sizemodifier; - weaponrenderparams[WEAPON_TYPE_ROCKET].offsetx = 24.0f; - weaponrenderparams[WEAPON_TYPE_ROCKET].offsety = -2.0f; - weapontexcoordcursor[WEAPON_TYPE_ROCKET].x = 0; - weapontexcoordcursor[WEAPON_TYPE_ROCKET].y = 8; - weapontexcoordcursor[WEAPON_TYPE_ROCKET].w = 2; - weapontexcoordcursor[WEAPON_TYPE_ROCKET].h = 2; - weapontexcoord[WEAPON_TYPE_ROCKET].x = 2; - weapontexcoord[WEAPON_TYPE_ROCKET].y = 8; - weapontexcoord[WEAPON_TYPE_ROCKET].w = 7; - weapontexcoord[WEAPON_TYPE_ROCKET].h = 2; - weaponprojtexcoord[WEAPON_TYPE_ROCKET].x = 10; - weaponprojtexcoord[WEAPON_TYPE_ROCKET].y = 8; - weaponprojtexcoord[WEAPON_TYPE_ROCKET].w = 2; - weaponprojtexcoord[WEAPON_TYPE_ROCKET].h = 2; - - /*weaponrenderparams[WEAPON_TYPE_SNIPER].sizex = 60.0f; - weaponrenderparams[WEAPON_TYPE_SNIPER].sizey = 20.0f; - weaponrenderparams[WEAPON_TYPE_SNIPER].offsetx = 16.0f; - weaponrenderparams[WEAPON_TYPE_SNIPER].offsety = 4.0f; - weapontexcoordcursor[WEAPON_TYPE_SNIPER].x = 0; - weapontexcoordcursor[WEAPON_TYPE_SNIPER].y = 6; - weapontexcoordcursor[WEAPON_TYPE_SNIPER].w = 2; - weapontexcoordcursor[WEAPON_TYPE_SNIPER].h = 2; - weapontexcoord[WEAPON_TYPE_SNIPER].x = 3; - weapontexcoord[WEAPON_TYPE_SNIPER].y = 6; - weapontexcoord[WEAPON_TYPE_SNIPER].w = 6; - weapontexcoord[WEAPON_TYPE_SNIPER].h = 2; - weaponprojtexcoord[WEAPON_TYPE_SNIPER].x = 10; - weaponprojtexcoord[WEAPON_TYPE_SNIPER].y = 6; - weaponprojtexcoord[WEAPON_TYPE_SNIPER].w = 1; - weaponprojtexcoord[WEAPON_TYPE_SNIPER].h = 1;*/ - - weaponrenderparams[WEAPON_TYPE_SHOTGUN].sizex = 80.0f * sizemodifier; - weaponrenderparams[WEAPON_TYPE_SHOTGUN].sizey = 20.0f * sizemodifier; - weaponrenderparams[WEAPON_TYPE_SHOTGUN].offsetx = 24.0f; - weaponrenderparams[WEAPON_TYPE_SHOTGUN].offsety = -2.0f; - weapontexcoordcursor[WEAPON_TYPE_SHOTGUN].x = 0; - weapontexcoordcursor[WEAPON_TYPE_SHOTGUN].y = 6; - weapontexcoordcursor[WEAPON_TYPE_SHOTGUN].w = 2; - weapontexcoordcursor[WEAPON_TYPE_SHOTGUN].h = 2; - weapontexcoord[WEAPON_TYPE_SHOTGUN].x = 2; - weapontexcoord[WEAPON_TYPE_SHOTGUN].y = 6; - weapontexcoord[WEAPON_TYPE_SHOTGUN].w = 8; - weapontexcoord[WEAPON_TYPE_SHOTGUN].h = 2; - weaponprojtexcoord[WEAPON_TYPE_SHOTGUN].x = 10; - weaponprojtexcoord[WEAPON_TYPE_SHOTGUN].y = 6; - weaponprojtexcoord[WEAPON_TYPE_SHOTGUN].w = 2; - weaponprojtexcoord[WEAPON_TYPE_SHOTGUN].h = 2; - - nummuzzletex[WEAPON_TYPE_SHOTGUN] = 3; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][0].x = 12; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][0].y = 6; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][0].w = 3; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][0].h = 2; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][1].x = 16; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][1].y = 6; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][1].w = 3; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][1].h = 2; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][2].x = 20; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][2].y = 6; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][2].w = 3; - muzzletexcoord[WEAPON_TYPE_SHOTGUN][2].h = 2; - - muzzleparams[WEAPON_TYPE_SHOTGUN].sizex = 60.0f * sizemodifier; - muzzleparams[WEAPON_TYPE_SHOTGUN].sizey = 40.0f * sizemodifier; - muzzleparams[WEAPON_TYPE_SHOTGUN].offsetx = 50.0f * sizemodifier; - muzzleparams[WEAPON_TYPE_SHOTGUN].offsety = 6.0f * sizemodifier; - - - - weaponrenderparams[WEAPON_TYPE_MELEE].sizex = 60.0f * sizemodifier; - weaponrenderparams[WEAPON_TYPE_MELEE].sizey = 50.0f * sizemodifier; - weaponrenderparams[WEAPON_TYPE_MELEE].offsetx = 20.0f; - weaponrenderparams[WEAPON_TYPE_MELEE].offsety = -4.0f; - weapontexcoordcursor[WEAPON_TYPE_MELEE].x = 0; - weapontexcoordcursor[WEAPON_TYPE_MELEE].y = 0; - weapontexcoordcursor[WEAPON_TYPE_MELEE].w = 2; - weapontexcoordcursor[WEAPON_TYPE_MELEE].h = 2; - weapontexcoord[WEAPON_TYPE_MELEE].x = 2; - weapontexcoord[WEAPON_TYPE_MELEE].y = 1; - weapontexcoord[WEAPON_TYPE_MELEE].w = 4; - weapontexcoord[WEAPON_TYPE_MELEE].h = 3; - weaponprojtexcoord[WEAPON_TYPE_MELEE].x = 0; - weaponprojtexcoord[WEAPON_TYPE_MELEE].y = 0; - weaponprojtexcoord[WEAPON_TYPE_MELEE].w = 0; - weaponprojtexcoord[WEAPON_TYPE_MELEE].h = 0; - - - // MODIFIERS - sizemodifier = 2.0; - modifierrenderparams[MODIFIER_TYPE_NINJA].sizex = 60.0f * sizemodifier; - modifierrenderparams[MODIFIER_TYPE_NINJA].sizey = 20.0f * sizemodifier; - modifierrenderparams[MODIFIER_TYPE_NINJA].offsetx = 20.0f; - modifierrenderparams[MODIFIER_TYPE_NINJA].offsety = 4.0f; - modifiertexcoord[MODIFIER_TYPE_NINJA].x = 2; - modifiertexcoord[MODIFIER_TYPE_NINJA].y = 10; - modifiertexcoord[MODIFIER_TYPE_NINJA].w = 7; - modifiertexcoord[MODIFIER_TYPE_NINJA].h = 2; - modifiertexcoordcursor[MODIFIER_TYPE_NINJA].x = 0; - modifiertexcoordcursor[MODIFIER_TYPE_NINJA].y = 10; - modifiertexcoordcursor[MODIFIER_TYPE_NINJA].w = 2; - modifiertexcoordcursor[MODIFIER_TYPE_NINJA].h = 2; - - modifierrenderparams[MODIFIER_TYPE_TIMEFIELD].sizex = 60.0f * sizemodifier; - modifierrenderparams[MODIFIER_TYPE_TIMEFIELD].sizey = 20.0f * sizemodifier; - modifierrenderparams[MODIFIER_TYPE_TIMEFIELD].offsetx = 16.0f; - modifierrenderparams[MODIFIER_TYPE_TIMEFIELD].offsety = 4.0f; - modifiertexcoord[MODIFIER_TYPE_TIMEFIELD].x = 0; - modifiertexcoord[MODIFIER_TYPE_TIMEFIELD].y = 0; - modifiertexcoord[MODIFIER_TYPE_TIMEFIELD].w = 0; - modifiertexcoord[MODIFIER_TYPE_TIMEFIELD].h = 0; - - stars[0].x = 0; - stars[0].y = 0; - stars[0].w = 2; - stars[0].h = 2; - - stars[1].x = 0; - stars[1].y = 2; - stars[1].w = 2; - stars[1].h = 2; - - particlecolors[0].x = 0.7f; - particlecolors[0].y = 0.7f; - particlecolors[0].z = 0.7f; - particlecolors[0].w = 1.0f; - particlestexcoord[0].x = 2; - particlestexcoord[0].y = 0; - particlestexcoord[0].w = 2; - particlestexcoord[0].h = 2; - particlecolors[1].x = 1.0f; - particlecolors[1].y = 1.0f; - particlecolors[1].z = 1.0f; - particlecolors[1].w = 1.0f; - particlestexcoord[1].x = 4; - particlestexcoord[1].y = 0; - particlestexcoord[1].w = 2; - particlestexcoord[1].h = 2; - particlecolors[2].x = 0.8f; - particlecolors[2].y = 0.8f; - particlecolors[2].z = 0.8f; - particlecolors[2].w = 1.0f; - particlestexcoord[2].x = 6; - particlestexcoord[2].y = 0; - particlestexcoord[2].w = 2; - particlestexcoord[2].h = 2; - particlecolors[3].x = 0.988f; - particlecolors[3].y = 1.0f; - particlecolors[3].z = 0.16f; - particlecolors[3].w = 1.0f; - particlestexcoord[3].x = 8; - particlestexcoord[3].y = 0; - particlestexcoord[3].w = 2; - particlestexcoord[3].h = 2; - particlecolors[4].x = 1.0f; - particlecolors[4].y = 1.0f; - particlecolors[4].z = 1.0f; - particlecolors[4].w = 1.0f; - particlestexcoord[4].x = 10; - particlestexcoord[4].y = 0; - particlestexcoord[4].w = 2; - particlestexcoord[4].h = 2; - particlecolors[5].x = 0.6f; - particlecolors[5].y = 0.6f; - particlecolors[5].z = 0.6f; - particlecolors[5].w = 1.0f; - particlestexcoord[5].x = 2; - particlestexcoord[5].y = 2; - particlestexcoord[5].w = 2; - particlestexcoord[5].h = 2; - particlecolors[6].x = 1.0f; - particlecolors[6].y = 1.0f; - particlecolors[6].z = 1.0f; - particlecolors[6].w = 1.0f; - particlestexcoord[6].x = 4; - particlestexcoord[6].y = 2; - particlestexcoord[6].w = 2; - particlestexcoord[6].h = 2; - particlecolors[5].x = 0.9f; - particlecolors[5].y = 0.9f; - particlecolors[5].z = 0.9f; - particlecolors[5].w = 1.0f; - particlestexcoord[7].x = 6; - particlestexcoord[7].y = 2; - particlestexcoord[7].w = 2; - particlestexcoord[7].h = 2; - particlecolors[8].x = 1.0f; - particlecolors[8].y = 1.0f; - particlecolors[8].z = 1.0f; - particlecolors[8].w = 1.0f; - particlestexcoord[8].x = 8; - particlestexcoord[8].y = 2; - particlestexcoord[8].w = 2; - particlestexcoord[8].h = 2; - lifemodifier[0] = 0.5f; - lifemodifier[1] = 0.5f; - lifemodifier[2] = 0.5f; - lifemodifier[3] = 0.7f; - lifemodifier[4] = 0.7f; - lifemodifier[5] = 1.0f; - lifemodifier[6] = 1.0f; - lifemodifier[7] = 1.5f; - lifemodifier[8] = 0.4f; - - chaintexcoord.x = 2; - chaintexcoord.y = 0; - chaintexcoord.w = 1; - chaintexcoord.h = 1; - - chainheadtexcoord.x = 3; - chainheadtexcoord.y = 0; - chainheadtexcoord.w = 2; - chainheadtexcoord.h = 1; - - - // anims - anim::setup_hammer(hammeranim); - anim::setup_ninja(ninjaanim); - - for (int i = 0; i < NUMHADOKENS; i++) - { - hadoken[i].x = 1; - hadoken[i].y = 12; - hadoken[i].w = 7; - hadoken[i].h = 4; - hadokenparams[i].sizex = 0.0f; - hadokenparams[i].sizey = 0.0f; - hadokenparams[i].offsetx = 0.0f; - hadokenparams[i].offsety = 0.0f;//-hadokenparams[0].sizey * 0.15f; - } - - // hadoken - hadoken[0].x = 1; - hadoken[0].y = 12; - hadoken[0].w = 7; - hadoken[0].h = 4; - hadokenparams[0].sizex = 70.0f * 2.5f; - hadokenparams[0].sizey = 40.0f * 2.5f; - hadokenparams[0].offsetx = -60.0f; - hadokenparams[0].offsety = 0;//-hadokenparams[0].sizey * 0.15f; - - hadoken[2].x = 8; - hadoken[2].y = 12; - hadoken[2].w = 8; - hadoken[2].h = 4; - hadokenparams[2].sizex = 80.0f * 2.5f; - hadokenparams[2].sizey = 40.0f * 2.5f; - hadokenparams[2].offsetx = -60.0f; - hadokenparams[2].offsety = 0;//-hadokenparams[1].sizey * 0.5f; - - hadoken[4].x = 17; - hadoken[4].y = 12; - hadoken[4].w = 7; - hadoken[4].h = 4; - hadokenparams[4].sizex = 70.0f * 2.5f; - hadokenparams[4].sizey = 40.0f * 2.5f; - hadokenparams[4].offsetx = -60.0f; - hadokenparams[4].offsety = 0;//-hadokenparams[2].sizey * 0.5f; - - // 0 = outline, 1 = body - body[0].x = 2; - body[0].y = 0; - body[0].w = 2; - body[0].h = 2; - body[1].x = 0; - body[1].y = 0; - body[1].w = 2; - body[1].h = 2; - - feet[0].x = 4; - feet[0].y = 1; - feet[0].w = 1; - feet[0].h = 0.5; - feet[1].x = 4; - feet[1].y = 1.52; - feet[1].w = 1; - feet[1].h = 0.48; + for(int s = 0; s < data->num_sounds; s++) + for(int i = 0; i < data->sounds[s].num_sounds; i++) + data->sounds[s].sounds[i].id = snd_load_wav(data->sounds[s].sounds[i].filename); - leye.x = 5; - leye.y = 1; - leye.w = 0.5; - leye.h = 0.5; - - reye.x = 5; - reye.y = 1.0; - reye.w = 0.5; - reye.h = 0.5; + // load textures + for(int i = 0; i < data->num_images; i++) + data->images[i].id = gfx_load_texture(data->images[i].filename); } void modc_entergame() @@ -1179,77 +447,17 @@ void modc_newsnapshot() { ev_sound *ev = (ev_sound *)data; vec2 p(ev->x, ev->y); - int sound = (ev->sound & SOUND_MASK); + int soundid = ev->sound; //(ev->sound & SOUND_MASK); //bool bstartloop = (ev->sound & SOUND_LOOPFLAG_STARTLOOP) != 0; //bool bstoploop = (ev->sound & SOUND_LOOPFLAG_STOPLOOP) != 0; float vol, pan; sound_vol_pan(p, &vol, &pan); - - switch(sound) + + if(soundid >= 0 && soundid < NUM_SOUNDS) { - - // FIRE! - case SOUND_FIRE_GUN: - sound_gun_fire.play_random(volume_gun*vol, pan); - break; - case SOUND_FIRE_SHOTGUN: - sound_shotty_fire.play_random(volume_gun*vol, pan); - break; - case SOUND_FIRE_ROCKET: - sound_flump_launch.play_random(volume_gun*vol, pan); - break; - case SOUND_FIRE_MELEE: - sound_hammer_swing.play_random(volume_gun*vol, pan); - break; - case SOUND_FIRE_NINJA: - sound_ninja_attack.play_random(volume_gun*vol, pan); - break; - - // IMPACT - case SOUND_IMPACT_PROJECTILE_GUN: - break; - case SOUND_IMPACT_PROJECTILE_SHOTGUN: - break; - case SOUND_IMPACT_PROJECTILE_ROCKET: - sound_flump_explode.play_random(volume_hit*vol, pan); - break; - - // PLAYER - case SOUND_PLAYER_JUMP: - sound_body_jump.play_random(volume_tee*vol, pan); - break; - case SOUND_PLAYER_HURT_SHORT: - sound_pain_short.play_random(volume_tee*vol, pan); - break; - case SOUND_PLAYER_HURT_LONG: - sound_pain_long.play_random(volume_tee*vol, pan); - break; - case SOUND_PLAYER_SPAWN: - sound_spawn.play_random(volume_tee*vol, pan); - break; - case SOUND_PLAYER_CHAIN_LOOP: - sound_hook_loop.play_random(volume_gun*vol, pan); - break; - case SOUND_PLAYER_CHAIN_IMPACT: - sound_hook_attach.play_random(volume_gun*vol, pan); - break; - case SOUND_PLAYER_IMPACT: - sound_body_land.play_random(volume_hit*vol, pan); - break; - case SOUND_PLAYER_IMPACT_NINJA: - sound_ninja_hit.play_random(volume_hit*vol, pan); - break; - case SOUND_PLAYER_DIE: - sound_body_splat.play_random(volume_tee*vol, pan); - break; - case SOUND_PLAYER_SWITCHWEAPON: - sound_weapon_switch.play_random(volume_gun*vol, pan); - break; - case SOUND_PLAYER_EQUIP: - break; - case SOUND_PLAYER_LAND: - sound_body_land.play_random(volume_tee*vol, pan); - break; + // TODO: we need to control the volume of the diffrent sounds + // depening on the category + snd_play_random(soundid, vol, pan); } } } @@ -1257,9 +465,10 @@ void modc_newsnapshot() static void render_projectile(obj_projectile *prev, obj_projectile *current) { - gfx_texture_set(texture_weapon); + gfx_texture_set(data->images[IMAGE_WEAPONS].id); gfx_quads_begin(); - cell_select_ex(numcellsx,numcellsy,weaponprojtexcoord[current->type].x, weaponprojtexcoord[current->type].y, weaponprojtexcoord[current->type].w, weaponprojtexcoord[current->type].h); + + select_sprite(data->weapons[current->type%data->num_weapons].sprite_proj); vec2 vel(current->vx, current->vy); // TODO: interpolare angle aswell @@ -1268,7 +477,7 @@ static void render_projectile(obj_projectile *prev, obj_projectile *current) else gfx_quads_setrotation(0); - vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), snap_intratick()); + vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick()); gfx_quads_draw(pos.x, pos.y,32,32); gfx_quads_setrotation(0); gfx_quads_end(); @@ -1276,163 +485,155 @@ static void render_projectile(obj_projectile *prev, obj_projectile *current) static void render_powerup(obj_powerup *prev, obj_powerup *current) { - //dbg_msg("client", "rendering powerup at %d,%d", current->x, current->y); - - gfx_texture_set(texture_weapon); + gfx_texture_set(data->images[IMAGE_WEAPONS].id); gfx_quads_begin(); float angle = 0.0f; - float sizex = 64.0f; - float sizey = 64.0f; + float size = 64.0f; if (current->type == POWERUP_TYPE_WEAPON) { angle = -0.25f * pi * 2.0f; - cell_select_ex(numcellsx,numcellsy,weapontexcoord[current->subtype].x, weapontexcoord[current->subtype].y, weapontexcoord[current->subtype].w, weapontexcoord[current->subtype].h); - sizex = weaponrenderparams[current->subtype].sizex; - sizey = weaponrenderparams[current->subtype].sizey; + select_sprite(data->weapons[current->subtype%data->num_weapons].sprite_body); + size = data->weapons[current->subtype%data->num_weapons].visual_size; } else - cell_select_ex(numcellsx,numcellsy,poweruptexcoord[current->type].x, poweruptexcoord[current->type].y, poweruptexcoord[current->type].w, poweruptexcoord[current->type].h); - vec2 vel(current->vx, current->vy); + { + const int c[] = { + SPRITE_POWERUP_HEALTH, + SPRITE_POWERUP_ARMOR, + SPRITE_POWERUP_WEAPON, + SPRITE_POWERUP_NINJA, + SPRITE_POWERUP_TIMEFIELD + }; + select_sprite(c[current->type]); + } gfx_quads_setrotation(angle); - // TODO: interpolare angle aswell - /*if(length(vel) > 0.00001f) - gfx_quads_setrotation(get_angle(vel)); - else - gfx_quads_setrotation(0);*/ - vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), snap_intratick()); + vec2 pos = mix(vec2(prev->x, prev->y), vec2(current->x, current->y), client_intratick()); float offset = pos.y/32.0f + pos.x/32.0f; - gfx_quads_draw(pos.x+cosf(client_localtime()*2.0f+offset)*2.5f, pos.y+sinf(client_localtime()*2.0f+offset)*2.5f,sizex * 0.65f,sizey * 0.65f); - gfx_quads_setrotation(0); + pos.x += cosf(client_localtime()*2.0f+offset)*2.5f; + pos.y += sinf(client_localtime()*2.0f+offset)*2.5f; + draw_sprite(pos.x, pos.y, size); gfx_quads_end(); } -float getmeleeangle(vec2 direction, obj_player* prev, obj_player* player) +static void anim_seq_eval(sequence *seq, float time, keyframe *frame) { - vec2 meleedir(0.53, -0.84); - meleedir = normalize(meleedir); - vec2 meleedirattack(0.95, -0.3); - meleedirattack = normalize(meleedirattack); - - if(direction.x < 0) + if(seq->num_frames == 0) { - meleedir.x = -meleedir.x; - meleedirattack.x = -meleedirattack.x; + frame->time = 0; + frame->x = 0; + frame->y = 0; + frame->angle = 0; } - - // 0 -> visualtimeattack go to end pose, (len - visualime) -> go back to normal pose - - float angle = get_angle(meleedir); - if (prev->attackticks) + else if(seq->num_frames == 1) + { + *frame = seq->frames[0]; + } + else { - float angleattack = get_angle(meleedirattack); - int phase1tick = (player->attacklen - player->attackticks); - if (phase1tick < player->visualtimeattack) + //time = max(0.0f, min(1.0f, time / duration)); // TODO: use clamp + keyframe *frame1 = 0; + keyframe *frame2 = 0; + float blend = 0.0f; + + // TODO: make this smarter.. binary search + for (int i = 1; i < seq->num_frames; i++) { - float intratick = snap_intratick(); - float t = ((((float)phase1tick) + intratick)/(float)player->visualtimeattack); - angle = LERP(angle, angleattack, min(1.0f,max(0.0f,t))); - } - else + if (seq->frames[i-1].time <= time && seq->frames[i].time >= time) + { + frame1 = &seq->frames[i-1]; + frame2 = &seq->frames[i]; + blend = (time - frame1->time) / (frame2->time - frame1->time); + break; + } + } + + if (frame1 && frame2) { - // go back to normal pose - int phase2tick = (player->attacklen - player->visualtimeattack - player->attackticks); - float intratick = snap_intratick(); - float t = ((((float)phase2tick) + intratick)/(float)player->visualtimeattack); - angle = LERP(angleattack, angle, min(1.0f,max(0.0f,t))); + frame->time = time; + frame->x = mix(frame1->x, frame2->x, blend); + frame->y = mix(frame1->y, frame2->y, blend); + frame->angle = mix(frame1->angle, frame2->angle, blend); } } - /*if (prev->attackticks && !player->attackticks) - { - // blend back to normal - float angleattack = get_angle(meleedirattack); - angle = LERP(angleattack, angle, min(1.0f,max(0.0f,snap_intratick()))); - } - else if (player->attackticks) - { - float angleattack = get_angle(meleedirattack); - float intratick = snap_intratick(); - float t = ((((float)player->attackticks) - intratick)/(float)player->attacklen); - angle = LERP(angleattack, angle, min(1.0f,max(0.0f,t))); - }*/ - - return angle; } -float gethammereangle(vec2 direction, obj_player* prev, obj_player* player) +struct animstate { - float t = 0.0f; - if (prev->attackticks) - t = 1.0f - ((((float)player->attackticks) - snap_intratick())/(float)player->attacklen); + keyframe body; + keyframe back_foot; + keyframe front_foot; + keyframe attach; +}; - vec2 pos; - float angle = 0.0f; - hammeranim.evalanim(t,pos,angle); - if(direction.x < 0) - angle = pi -angle;// + ; - //dbg_msg("anim", "Time: %f", t); - return angle; +static void anim_eval(animation *anim, float time, animstate *state) +{ + anim_seq_eval(&anim->body, time, &state->body); + anim_seq_eval(&anim->back_foot, time, &state->back_foot); + anim_seq_eval(&anim->front_foot, time, &state->front_foot); + anim_seq_eval(&anim->attach, time, &state->attach); } -float getninjaangle(vec2 direction, obj_player* prev, obj_player* player) +static void anim_add_keyframe(keyframe *seq, keyframe *added, float amount) { - float t = 0.0f; - if (prev->attackticks) - t = 1.0f - ((((float)player->attackticks) - snap_intratick())/(float)player->attacklen); - - vec2 pos; - float angle = 0.0f; - ninjaanim.evalanim(t,pos,angle); - if(direction.x < 0) - angle = pi -angle;// + ; - //dbg_msg("anim", "Time: %f", t); - return angle; + seq->x += added->x*amount; + seq->y += added->y*amount; + seq->angle += added->angle*amount; } +static void anim_add(animstate *state, animstate *added, float amount) +{ + anim_add_keyframe(&state->body, &added->body, amount); + anim_add_keyframe(&state->back_foot, &added->back_foot, amount); + anim_add_keyframe(&state->front_foot, &added->front_foot, amount); + anim_add_keyframe(&state->attach, &added->attach, amount); +} -float getrecoil(obj_player* prev, obj_player* player) +static void anim_eval_add(animstate *state, animation *anim, float time, float amount) { - // attack = -10 - float recoil = 0.0f; - if (prev->attackticks) - { - float attackrecoil = recoils[player->weapon]; - int phase1tick = (player->attacklen - player->attackticks); - if (phase1tick < player->visualtimeattack) - { - float intratick = snap_intratick(); - float t = ((((float)phase1tick) + intratick)/(float)player->visualtimeattack); - recoil = LERP(0, attackrecoil, min(1.0f,max(0.0f,t))); - } - else - { - // go back to normal pose - int phase2tick = (player->attacklen - player->visualtimeattack - player->attackticks); - float intratick = snap_intratick(); - float t = ((((float)phase2tick) + intratick)/(float)(player->attacklen - player->visualtimeattack)); - recoil = LERP(attackrecoil, 0.0f, min(1.0f,max(0.0f,t))); - } - } - return recoil; + animstate add; + anim_eval(anim, time, &add); + anim_add(state, &add, amount); } static void render_player(obj_player *prev, obj_player *player) { vec2 direction = get_direction(player->angle); float angle = player->angle/256.0f; - vec2 position = mix(vec2(prev->x, prev->y), vec2(player->x, player->y), snap_intratick()); + vec2 position = mix(vec2(prev->x, prev->y), vec2(player->x, player->y), client_intratick()); + bool stationary = player->vx < 1 && player->vx > -1; + bool inair = col_check_point(player->x, player->y+16) == 0; + + // evaluate animation + float walk_time = fmod(position.x, 100.0f)/100.0f; + animstate state; + anim_eval(&data->animations[ANIM_BASE], 0, &state); + + if(inair) + anim_eval_add(&state, &data->animations[ANIM_INAIR], 0, 1.0f); // TODO: some sort of time here + else if(stationary) + anim_eval_add(&state, &data->animations[ANIM_IDLE], 0, 1.0f); // TODO: some sort of time here + else + anim_eval_add(&state, &data->animations[ANIM_WALK], walk_time, 1.0f); + + if (player->weapon == WEAPON_HAMMER) + { + float a = clamp((client_tick()-player->attacktick+client_intratick())/7.5f, 0.0f, 1.0f); + anim_eval_add(&state, &data->animations[ANIM_HAMMER_SWING], a, 1.0f); + } + + // draw hook if(player->hook_active) { - gfx_texture_set(texture_weapon); + gfx_texture_set(data->images[IMAGE_WEAPONS].id); gfx_quads_begin(); //gfx_quads_begin(); vec2 pos = position; - - vec2 hook_pos = mix(vec2(prev->hook_x, prev->hook_y), vec2(player->hook_x, player->hook_y), snap_intratick()); + vec2 hook_pos = mix(vec2(prev->hook_x, prev->hook_y), vec2(player->hook_x, player->hook_y), client_intratick()); float d = distance(pos, hook_pos); vec2 dir = normalize(pos-hook_pos); @@ -1440,11 +641,11 @@ static void render_player(obj_player *prev, obj_player *player) gfx_quads_setrotation(get_angle(dir)+pi); // render head - cell_select_ex(numcellsx,numcellsy, chainheadtexcoord.x,chainheadtexcoord.y, chainheadtexcoord.w, chainheadtexcoord.h); + select_sprite(SPRITE_HOOK_HEAD); gfx_quads_draw(hook_pos.x, hook_pos.y, 24,16); // render chain - cell_select_ex(numcellsx,numcellsy, chaintexcoord.x, chaintexcoord.y, chaintexcoord.w, chaintexcoord.h); + select_sprite(SPRITE_HOOK_CHAIN); for(float f = 24; f < d; f += 24) { vec2 p = hook_pos + dir*f; @@ -1457,131 +658,51 @@ static void render_player(obj_player *prev, obj_player *player) // draw gun { - gfx_texture_set(texture_weapon); + gfx_texture_set(data->images[IMAGE_WEAPONS].id); gfx_quads_begin(); - gfx_quads_setrotation(angle); + gfx_quads_setrotation(state.attach.angle*pi*2+angle); + + // normal weapons + int iw = clamp(player->weapon, 0, NUM_WEAPONS-1); + select_sprite(data->weapons[iw].sprite_body, direction.x < 0 ? SPRITE_FLAG_FLIP_Y : 0); - if (player->modifier & (1 << MODIFIER_TYPE_NINJA)) + vec2 dir = direction; + float recoil = 0.0f; + if (player->weapon == WEAPON_HAMMER) { - float playerangle = angle; - // render NINJA!!! (0.53, 0.84) when idle to -> (0.95, 0.3) at the end of attack + // if attack is under way, bash stuffs if(direction.x < 0) - cell_select_ex_flip_y(numcellsx, numcellsy, modifiertexcoord[MODIFIER_TYPE_NINJA].x, modifiertexcoord[MODIFIER_TYPE_NINJA].y, modifiertexcoord[MODIFIER_TYPE_NINJA].w, modifiertexcoord[MODIFIER_TYPE_NINJA].h); + gfx_quads_setrotation(-pi/2-state.attach.angle*pi*2); else - cell_select_ex(numcellsx, numcellsy, modifiertexcoord[MODIFIER_TYPE_NINJA].x, modifiertexcoord[MODIFIER_TYPE_NINJA].y, modifiertexcoord[MODIFIER_TYPE_NINJA].w, modifiertexcoord[MODIFIER_TYPE_NINJA].h); - - angle = getninjaangle(direction, prev, player);//getmeleeangle(direction, prev, player); - vec2 ninjadir = get_direction((int)(angle * 256.0f)); // TODO: ugly, fix this - gfx_quads_setrotation(angle); - vec2 p = position + vec2(0,modifierrenderparams[MODIFIER_TYPE_NINJA].offsety)+ ninjadir * modifierrenderparams[MODIFIER_TYPE_NINJA].offsetx; - // if attack is active hold it differently and draw speedlines behind us? - gfx_quads_draw(p.x,p.y/*+bob*/,modifierrenderparams[MODIFIER_TYPE_NINJA].sizex, modifierrenderparams[MODIFIER_TYPE_NINJA].sizey); - - if ((player->attacklen - player->attackticks) <= (SERVER_TICK_SPEED / 5)) - { - gfx_quads_setrotation(playerangle); - int ihadoken = rand() % NUMHADOKENS; - cell_select_ex(numcellsx, numcellsy, hadoken[ihadoken].x, hadoken[ihadoken].y, hadoken[ihadoken].w, hadoken[ihadoken].h); - vec2 p = position + vec2(0,hadokenparams[ihadoken].offsety)+ direction * hadokenparams[ihadoken].offsetx; - gfx_quads_draw(p.x,p.y/*+bob*/,hadokenparams[ihadoken].sizex, hadokenparams[ihadoken].sizey); - } + gfx_quads_setrotation(-pi/2+state.attach.angle*pi*2); } else { - // normal weapons - if(direction.x < 0) - cell_select_ex_flip_y(numcellsx, numcellsy, weapontexcoord[player->weapon].x, weapontexcoord[player->weapon].y, weapontexcoord[player->weapon].w, weapontexcoord[player->weapon].h); - else - cell_select_ex(numcellsx, numcellsy, weapontexcoord[player->weapon].x, weapontexcoord[player->weapon].y, weapontexcoord[player->weapon].w, weapontexcoord[player->weapon].h); - - vec2 dir = direction; - float recoil = 0.0f; - if (player->weapon == WEAPON_TYPE_MELEE) - { - // if attack is under way, bash stuffs - //angle = getmeleeangle(direction, prev, player); - angle = gethammereangle(direction, prev, player); - gfx_quads_setrotation(angle); - dir = get_direction((int)(angle * 256.0f)); // TODO: ugly, fix this - } - else - { - recoil = getrecoil(prev, player); - } - - vec2 p = position + vec2(0,weaponrenderparams[player->weapon].offsety) + dir * weaponrenderparams[player->weapon].offsetx - dir * recoil; - gfx_quads_draw(p.x,p.y/*+bob*/,weaponrenderparams[player->weapon].sizex, weaponrenderparams[player->weapon].sizey); - // draw muzzleflare - if (player->weapon == WEAPON_TYPE_GUN || player->weapon == WEAPON_TYPE_SHOTGUN) - { - // check if we're firing stuff - if (true)///prev->attackticks) - { - float alpha = 0.0f; - int phase1tick = (player->attacklen - player->attackticks); - if (phase1tick < (player->visualtimeattack + 3)) - { - float intratick = snap_intratick(); - float t = ((((float)phase1tick) + intratick)/(float)player->visualtimeattack); - alpha = LERP(2.0, 0.0f, min(1.0f,max(0.0f,t))); - } - - if (alpha > 0.0f) - { - float offsety = -muzzleparams[player->weapon].offsety; - int itex = rand() % nummuzzletex[player->weapon]; - if(direction.x < 0) - { - offsety = -offsety; - cell_select_ex_flip_y(numcellsx, numcellsy, muzzletexcoord[player->weapon][itex].x, muzzletexcoord[player->weapon][itex].y, muzzletexcoord[player->weapon][itex].w, muzzletexcoord[player->weapon][itex].h); - } - else - cell_select_ex(numcellsx, numcellsy, muzzletexcoord[player->weapon][itex].x, muzzletexcoord[player->weapon][itex].y, muzzletexcoord[player->weapon][itex].w, muzzletexcoord[player->weapon][itex].h); - - gfx_quads_setcolor(1.0f,1.0f,1.0f,alpha); - vec2 diry(-dir.y,dir.x); - p += dir * muzzleparams[player->weapon].offsetx + diry * offsety; - gfx_quads_draw(p.x,p.y/*+bob*/,muzzleparams[player->weapon].sizex, muzzleparams[player->weapon].sizey); - } - } - } + // TODO: should be an animation + recoil = 0; + float a = (client_tick()-player->attacktick+client_intratick())/5.0f; + if(a < 1) + recoil = sinf(a*pi); } - /*else - { - // minigun - if(direction.x < 0) - cell_select_flip_y(4,4,8,2); - else - cell_select(4,4,8,2); - vec2 p = position + vec2(0,3); - gfx_quads_draw(p.x,p.y,8*8,8*2); - }*/ - - gfx_quads_setrotation(0); + + vec2 p = position + dir*20.0f - dir*recoil*10.0f; + draw_sprite(p.x, p.y, data->weapons[iw].visual_size); + + // TODO: draw muzzleflare gfx_quads_end(); } - - gfx_texture_set(texture_char_default); + gfx_texture_set(data->images[IMAGE_CHAR_DEFAULT].id); gfx_quads_begin(); - float bob = 0; - // draw foots - const float cyclelength = 128.0f; - const float steplength = 26; - const float lift = 4.0f; - bool stationary = player->vx < 1 && player->vx > -1; - bool inair = col_check_point(player->x, player->y+16) == 0; - for(int p = 0; p < 2; p++) { // first pass we draw the outline // second pass we draw the filling - //int v_offset = p?0:5; - int outline = p;// ? 1 : 0; - float offsety = charids[player->clientid % 16] * 2.0f; + int outline = p==0 ? 1 : 0; + int shift = charids[player->clientid%16]; for(int f = 0; f < 2; f++) { @@ -1589,138 +710,41 @@ static void render_player(obj_player *prev, obj_player *player) if(f == 1) { // draw body - float t = fmod(position.x, cyclelength/2)/(cyclelength/2); - bob = -sinf(pow(t,2)*pi) * 3; - cell_select_ex(charnumcellsx,charnumcellsy, body[outline].x,body[outline].y + offsety,body[outline].w,body[outline].h); - //cell_select_ex(16,16, 0,0+v_offset,4,4); - //const float size = 64.0f; - if(stationary || inair) - bob = 0; - gfx_quads_draw(position.x, position.y-5+bob, 4*basesize, 4*basesize); + select_sprite(outline?SPRITE_TEE_BODY_OUTLINE:SPRITE_TEE_BODY, 0, 0, shift*4); + gfx_quads_draw(position.x+state.body.x, position.y+state.body.y, 4*basesize, 4*basesize); // draw eyes if(p == 1) { - //cell_select_ex(16,16, 8,3,1,1); vec2 md = get_direction(player->angle); float mouse_dir_x = md.x; float mouse_dir_y = md.y; // normal - cell_select_ex(charnumcellsx,charnumcellsy, leye.x,leye.y + offsety,leye.w,leye.h); - gfx_quads_draw(position.x-4+mouse_dir_x*4, position.y-8+mouse_dir_y*3+bob, basesize, basesize); - cell_select_ex(charnumcellsx,charnumcellsy, reye.x,reye.y + offsety,reye.w,reye.h); - gfx_quads_draw(position.x+4+mouse_dir_x*4, position.y-8+mouse_dir_y*3+bob, basesize, basesize); + select_sprite(SPRITE_TEE_EYE_NORMAL, 0, 0, shift*4); + gfx_quads_draw(position.x-4+mouse_dir_x*4, position.y-8+mouse_dir_y*3, basesize, basesize); + gfx_quads_draw(position.x+4+mouse_dir_x*4, position.y-8+mouse_dir_y*3, basesize, basesize); } } // draw feet - //cell_select_ex(16,16, 5,2+v_offset, 2,2); - cell_select_ex(charnumcellsx,charnumcellsy, feet[outline].x,feet[outline].y + offsety, feet[outline].w,feet[outline].h); + select_sprite(outline?SPRITE_TEE_FOOT_OUTLINE:SPRITE_TEE_FOOT, 0, 0, shift*4); + + keyframe *foot = f ? &state.front_foot : &state.back_foot; + float w = basesize*2.5f; float h = basesize*1.425f; - if(inair) - { - float r = 0.0f; - if(player->vy < 0.0f) - r = player->vy/3.0f; - else - r = player->vy/15.0f; - - // clamp the rotation - if(r > 0.5f) r = 0.5f; - if(r < -0.5f) r = -0.5f; - - if(player->vx > 0.0f) - r *= -1.0f; - gfx_quads_setrotation(r); - gfx_quads_drawTL(position.x-4+f*7-w/2, position.y+16 - h, w, h); - gfx_quads_setrotation(0); - } - else if(stationary) - { - // stationary - gfx_quads_drawTL(position.x-7+f*14-w/2, position.y+16 - h, w, h); - } - else - { - /* - The walk cycle, 2 parts - - 111 - 1 1 - 2 1 - 2 1 - 2222221 - GROUND GROUND GROUND - */ - - // moving - float tx = position.x+f*(cyclelength/2); - float t = fmod(tx, cyclelength) / cyclelength; - if(player->vx < 0) - t = 1.0f-t; - - float y; - float x = 0; - float r = 0; - float r_back = 1.5f; - - if(t < 0.5f) - { - // stomp down foot (part 1) - float st = t*2; - y = 1.0f-pow(st, 0.5f) + sinf(pow(st,2)*pi)*0.5f; - x = -steplength/2 + st*steplength; - r = r_back*(1-st) + sinf(pow(st,1.5f)*pi*2); - } - else - { - // lift foot up again (part 2) - float st = (t-0.5f)*2; - y = pow(st, 5.0f); - x = steplength/2 - st*steplength; - r = y*r_back; - } - - - if(player->vx > 0) - { - gfx_quads_setrotation(r); - gfx_quads_drawTL(position.x+x-w/2, position.y+16-y*lift - h, w, h); - } - else - { - gfx_quads_setrotation(-r); - gfx_quads_drawTL(position.x-x-w/2, position.y+16-y*lift - h, w, h); - } - gfx_quads_setrotation(0); - } - + + gfx_quads_setrotation(foot->angle); + gfx_quads_draw(position.x+foot->x, position.y+foot->y, w, h); } } gfx_quads_end(); - - } -static player_input oldinput; -static bool bfirst = true; void modc_render() { - if (bfirst) - { - bfirst = false; - oldinput.activeweapon = 0; - oldinput.angle = 0; - oldinput.blink = 0; - oldinput.fire = 0; - oldinput.hook = 0; - oldinput.jump = 0; - oldinput.left = 0; - oldinput.right = 0; - } // fetch new input { int x, y; @@ -1734,31 +758,27 @@ void modc_render() // snap input { player_input input; - input.left = inp_key_pressed(config.key_move_left); - input.right = inp_key_pressed(config.key_move_right); + mem_zero(&input, sizeof(input)); + float a = atan((float)mouse_pos.y/(float)mouse_pos.x); if(mouse_pos.x < 0) a = a+pi; + input.angle = (int)(a*256.0f); + input.left = inp_key_pressed(config.key_move_left); + input.right = inp_key_pressed(config.key_move_right); input.jump = inp_key_pressed(config.key_jump); - - input.fire = inp_key_pressed(config.key_fire);// | (oldinput.fire << 16); - //oldinput.fire = input.fire & 0x0000ffff; - + input.fire = inp_key_pressed(config.key_fire); input.hook = inp_key_pressed(config.key_hook); input.blink = inp_key_pressed('S'); // Weapon switching - input.activeweapon = inp_key_pressed('1') ? 0x80000000 : 0; - if (!input.activeweapon) - input.activeweapon = inp_key_pressed('2') ? 0x80000000 | 1 : 0; - if (!input.activeweapon) - input.activeweapon = inp_key_pressed('3') ? 0x80000000 | 2 : 0; - if (!input.activeweapon) - input.activeweapon = inp_key_pressed('4') ? 0x80000000 | 3 : 0; - /*if (!input.activeweapon) - input.activeweapon = inp_key_pressed('5') ? 0x80000000 | 4 : 0;*/ + input.activeweapon = -1; + input.activeweapon = inp_key_pressed('1') ? 0 : input.activeweapon; + input.activeweapon = inp_key_pressed('2') ? 1 : input.activeweapon; + input.activeweapon = inp_key_pressed('3') ? 2 : input.activeweapon; + input.activeweapon = inp_key_pressed('4') ? 3 : input.activeweapon; snap_input(&input, sizeof(input)); } @@ -1767,7 +787,6 @@ void modc_render() { // 1. fetch local player // 2. set him to the center - int num = snap_num_items(SNAP_CURRENT); for(int i = 0; i < num; i++) { @@ -1784,7 +803,7 @@ void modc_render() void *p = snap_find_item(SNAP_PREV, item.type, item.id); if(p) - local_player_pos = mix(vec2(((obj_player *)p)->x, ((obj_player *)p)->y), local_player_pos, snap_intratick()); + local_player_pos = mix(vec2(((obj_player *)p)->x, ((obj_player *)p)->y), local_player_pos, client_intratick()); break; } } @@ -1816,9 +835,9 @@ void modc_render() // draw background gfx_clear(0.65f,0.78f,0.9f); - - { + // draw the sun + { vec2 pos(local_player_pos.x*0.5f, local_player_pos.y*0.5f); gfx_texture_set(-1); @@ -1833,8 +852,6 @@ void modc_render() vec2 dir0(sinf((a-size)*pi*2.0f), cosf((a-size)*pi*2.0f)); vec2 dir1(sinf((a+size)*pi*2.0f), cosf((a+size)*pi*2.0f)); - //gfx_quads_draw_freeform(0,0, -100,0, -100,-100, 0,-100); - gfx_quads_setcolorvertex(0, 1.0f,1.0f,1.0f,0.025f); gfx_quads_setcolorvertex(1, 1.0f,1.0f,1.0f,0.025f); gfx_quads_setcolorvertex(2, 1.0f,1.0f,1.0f,0.0f); @@ -1849,7 +866,7 @@ void modc_render() gfx_quads_end(); gfx_blend_normal(); - gfx_texture_set(texture_sun); + gfx_texture_set(data->images[IMAGE_SUN].id); gfx_quads_begin(); gfx_quads_draw(pos.x, pos.y, 256, 256); gfx_quads_end(); @@ -1857,9 +874,6 @@ void modc_render() // render map tilemap_render(32.0f, 0); -#ifdef _DEBUG - float speed = 0.0f; -#endif // render items int num = snap_num_items(SNAP_CURRENT); for(int i = 0; i < num; i++) @@ -1871,18 +885,7 @@ void modc_render() { void *prev = snap_find_item(SNAP_PREV, item.type, item.id); if(prev) - { render_player((obj_player *)prev, (obj_player *)data); -/*#ifdef _DEBUG - { - obj_player *p = (obj_player *)prev; - obj_player *c = (obj_player *)data; - vec2 positionold = vec2(p->x, p->y); - vec2 poscur = vec2(c->x, c->y); - speed = distance(positionold,poscur); - } -#endif*/ - } } else if(item.type == OBJTYPE_PROJECTILE) { @@ -1907,68 +910,58 @@ void modc_render() // render health mods healthmods.render(); - // render cursor - // FIXME CURSOR!!! - if(local_player) { - gfx_texture_set(texture_weapon); + gfx_texture_set(data->images[IMAGE_WEAPONS].id); gfx_quads_begin(); - if (local_player->modifier & (1 << MODIFIER_TYPE_NINJA)) - cell_select_ex(numcellsx,numcellsy, modifiertexcoordcursor[MODIFIER_TYPE_NINJA].x, modifiertexcoordcursor[MODIFIER_TYPE_NINJA].y, modifiertexcoordcursor[MODIFIER_TYPE_NINJA].w, modifiertexcoordcursor[MODIFIER_TYPE_NINJA].h); - else - cell_select_ex(numcellsx,numcellsy, weapontexcoordcursor[local_player->weapon].x, weapontexcoordcursor[local_player->weapon].y, weapontexcoordcursor[local_player->weapon].w, weapontexcoordcursor[local_player->weapon].h); + + // render cursor + select_sprite(data->weapons[local_player->weapon%data->num_weapons].sprite_cursor); float cursorsize = 64; - gfx_quads_draw(local_player_pos.x+mouse_pos.x, local_player_pos.y+mouse_pos.y,cursorsize,cursorsize); - + draw_sprite(local_player_pos.x+mouse_pos.x, local_player_pos.y+mouse_pos.y, cursorsize); // render ammo count // render gui stuff gfx_quads_end(); gfx_quads_begin(); gfx_mapscreen(0,0,400,300); - cell_select_ex(numcellsx,numcellsy, weaponprojtexcoord[local_player->weapon].x, weaponprojtexcoord[local_player->weapon].y, weaponprojtexcoord[local_player->weapon].w, weaponprojtexcoord[local_player->weapon].h); + select_sprite(data->weapons[local_player->weapon%data->num_weapons].sprite_proj); for (int i = 0; i < local_player->ammocount; i++) - { gfx_quads_drawTL(10+i*12,34,10,10); - } gfx_quads_end(); - gfx_texture_set(texture_game); + gfx_texture_set(data->images[IMAGE_GAME].id); gfx_quads_begin(); int h = 0; - cell_select_ex(32,16, 0,0, 4,4); + + // render health + select_sprite(SPRITE_HEALTH_FULL); for(; h < local_player->health; h++) gfx_quads_drawTL(10+h*12,10,10,10); - cell_select_ex(32,16, 5,0, 4,4); + select_sprite(SPRITE_HEALTH_EMPTY); for(; h < 10; h++) gfx_quads_drawTL(10+h*12,10,10,10); + // render armor meter h = 0; - cell_select_ex(32,16, 0,5, 4,4); + select_sprite(SPRITE_ARMOR_FULL); for(; h < local_player->armor; h++) gfx_quads_drawTL(10+h*12,22,10,10); - cell_select_ex(32,16, 5,5, 4,4); + select_sprite(SPRITE_ARMOR_EMPTY); for(; h < 10; h++) gfx_quads_drawTL(10+h*12,22,10,10); gfx_quads_end(); - - // render speed -/*#ifdef _DEBUG - gfx_texture_set(font_texture); - char text[256]; - sprintf(text,"speed: %f",speed); - gfx_quads_text(300,20,10,text); -#endif*/ } + // render gui stuff gfx_mapscreen(0,0,400,300); + // render score board if(inp_key_pressed(baselib::input::tab)) { - gfx_texture_set(font_texture); + gfx_texture_set(-1); gfx_quads_text(10, 50, 8, "Score Board"); int num = snap_num_items(SNAP_CURRENT); @@ -1984,8 +977,8 @@ void modc_render() if(player) { char buf[128]; - char name[32]; - snap_decode_string(player->name, name, 32); + char name[32] = "tjo"; + //snap_decode_string(player->name, name, 32); sprintf(buf, "%4d %s", player->score, name); gfx_quads_text(10, 50 + 10 * row, 8, buf); row++; |