player is now of type Player
This commit is contained in:
parent
47264c3da3
commit
a7846a48d9
36
src/fencer.c
36
src/fencer.c
|
@ -1,14 +1,18 @@
|
|||
#include "assets.h"
|
||||
#include "camera.h"
|
||||
#include "debug.h"
|
||||
#include "input.h"
|
||||
#include "physics_world.h"
|
||||
#include "program.h"
|
||||
#include "rigidbody.h"
|
||||
#include "spritesheet.h"
|
||||
#include "sprite.h"
|
||||
#include "tilemap.h"
|
||||
#include "player.h"
|
||||
#include <assert.h>
|
||||
|
||||
static Spritesheet* spr_player_standing = NULL;
|
||||
static Sprite* player = NULL;
|
||||
static Transform player_trans = IdentityTransform;
|
||||
static Player* player = NULL;
|
||||
|
||||
static Level* level = NULL;
|
||||
|
||||
|
@ -25,29 +29,41 @@ void cam_move_v(int val) {
|
|||
|
||||
static
|
||||
void play() {
|
||||
g_camera.fov = 40;
|
||||
spr_player_standing = spritesheet_load("assets/sprites/player.png", (IVector){128, 128});
|
||||
player = sprite_from_spritesheet(spr_player_standing, 0);
|
||||
player_trans.scale = (Vector){4.f, 4.f};
|
||||
sprite_set_origin(player, (Vector){0.25f, 1.f});
|
||||
|
||||
g_camera.fov = 40;
|
||||
|
||||
player = malloc(sizeof(Player));
|
||||
player->transform.scale = (Vector){4.f, 4.f};
|
||||
store_asset(player, free);
|
||||
player->sprite = sprite_from_spritesheet(spr_player_standing, 0);
|
||||
player->rigidbody = rigidbody_make(Player_as_Transformable(player));
|
||||
sprite_set_origin(player->sprite, (Vector){0.25f, 1.f});
|
||||
player->shape = shape_new((Vector[]){
|
||||
{-.1f, -.75f},
|
||||
{0.1f, -.75f},
|
||||
{0.1f, 0.00f},
|
||||
{-.1f, 0.00f}
|
||||
}, 4);
|
||||
|
||||
level = level_load("level_0");
|
||||
|
||||
input_add_axis_action(SDL_SCANCODE_LEFT, SDL_SCANCODE_RIGHT, &cam_move_h);
|
||||
input_add_axis_action(SDL_SCANCODE_DOWN, SDL_SCANCODE_UP, &cam_move_v);
|
||||
input_add_axis_action(SDL_SCANCODE_A, SDL_SCANCODE_D, &cam_move_h);
|
||||
input_add_axis_action(SDL_SCANCODE_S, SDL_SCANCODE_W, &cam_move_v);
|
||||
|
||||
physics_world_add_entity(Player_as_PhysicsEntity(player));
|
||||
}
|
||||
|
||||
static
|
||||
void tick() {
|
||||
g_camera.transform.position = vaddf(g_camera.transform.position, cam_speed);
|
||||
player_trans.position = g_camera.transform.position;
|
||||
player->transform.position = g_camera.transform.position;
|
||||
}
|
||||
|
||||
static
|
||||
void draw() {
|
||||
level_draw(level);
|
||||
sprite_draw(player, player_trans);
|
||||
sprite_entity_draw(Player_as_SpriteEntity(player));
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
|
|
Loading…
Reference in a new issue