minigun player
This commit is contained in:
parent
4ae6c3fdfb
commit
57eba3c089
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
SRC=main.c ninja.c keys.c bullet.c
|
SRC=main.c ninja.c keys.c bullet.c minigun.c
|
||||||
EXE=voleur
|
EXE=voleur
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
|
||||||
|
|
9
bullet.c
9
bullet.c
|
@ -20,6 +20,7 @@ Texture textures[BULLET_COUNT];
|
||||||
void bullet_load()
|
void bullet_load()
|
||||||
{
|
{
|
||||||
textures[BULLET_SHURIKEN] = LoadTexture("data/shuriken.png");
|
textures[BULLET_SHURIKEN] = LoadTexture("data/shuriken.png");
|
||||||
|
textures[BULLET_MINIGUN] = LoadTexture("data/bullet.png");
|
||||||
}
|
}
|
||||||
|
|
||||||
void bullet_spawn(BulletType type, Vector2 pos, float angle)
|
void bullet_spawn(BulletType type, Vector2 pos, float angle)
|
||||||
|
@ -47,6 +48,12 @@ void draw_bullets()
|
||||||
Vector2 toward = Vector2Normalize((Vector2) {cos(angle), sin(angle)});
|
Vector2 toward = Vector2Normalize((Vector2) {cos(angle), sin(angle)});
|
||||||
bullets[i].pos = Vector2Add(bullets[i].pos, Vector2Scale(toward, speed));
|
bullets[i].pos = Vector2Add(bullets[i].pos, Vector2Scale(toward, speed));
|
||||||
bullets[i].time -= GetFrameTime();
|
bullets[i].time -= GetFrameTime();
|
||||||
DrawTexture(textures[bullets[i].type], bullets[i].pos.x, bullets[i].pos.y, WHITE);
|
|
||||||
|
Texture t = textures[bullets[i].type];
|
||||||
|
Rectangle source = {0, 0, t.width, t.height};
|
||||||
|
Rectangle dest = {bullets[i].pos.x, bullets[i].pos.y, t.width, t.height};
|
||||||
|
Vector2 origin = {t.width/2, t.height/2};
|
||||||
|
|
||||||
|
DrawTexturePro(t, source, dest, origin, bullets[i].angle + 90, WHITE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
1
bullet.h
1
bullet.h
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
typedef enum BulletType {
|
typedef enum BulletType {
|
||||||
BULLET_SHURIKEN,
|
BULLET_SHURIKEN,
|
||||||
|
BULLET_MINIGUN,
|
||||||
BULLET_COUNT,
|
BULLET_COUNT,
|
||||||
} BulletType;
|
} BulletType;
|
||||||
|
|
||||||
|
|
Binary file not shown.
BIN
data/bullet.png
BIN
data/bullet.png
Binary file not shown.
Before Width: | Height: | Size: 215 B After Width: | Height: | Size: 204 B |
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 880 B |
20
main.c
20
main.c
|
@ -6,6 +6,13 @@
|
||||||
#include "bullet.h"
|
#include "bullet.h"
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
#include "ninja.h"
|
#include "ninja.h"
|
||||||
|
#include "minigun.h"
|
||||||
|
|
||||||
|
typedef enum PlayerType {
|
||||||
|
PLAYER_NINJA,
|
||||||
|
PLAYER_MINIGUN,
|
||||||
|
PLAYER_COUNT,
|
||||||
|
} PlayerType;
|
||||||
|
|
||||||
#define SCREEN_MIDDLE ((Vector2) {window_size.x/2, window_size.y/2})
|
#define SCREEN_MIDDLE ((Vector2) {window_size.x/2, window_size.y/2})
|
||||||
|
|
||||||
|
@ -70,7 +77,13 @@ int main(void)
|
||||||
|
|
||||||
change_layout_azerty();
|
change_layout_azerty();
|
||||||
|
|
||||||
load_ninja();
|
PlayerType player_type = PLAYER_MINIGUN;
|
||||||
|
|
||||||
|
if (player_type == PLAYER_NINJA)
|
||||||
|
load_ninja();
|
||||||
|
else if (player_type == PLAYER_MINIGUN)
|
||||||
|
load_minigun();
|
||||||
|
|
||||||
bullet_load();
|
bullet_load();
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
|
@ -114,7 +127,10 @@ int main(void)
|
||||||
draw_bullets();
|
draw_bullets();
|
||||||
}
|
}
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
draw_ninja(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera);
|
if (player_type == PLAYER_NINJA)
|
||||||
|
draw_ninja(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera);
|
||||||
|
else if (player_type == PLAYER_MINIGUN)
|
||||||
|
draw_minigun(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera);
|
||||||
}
|
}
|
||||||
EndDrawing();
|
EndDrawing();
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,38 @@
|
||||||
|
#include "raylib.h"
|
||||||
|
#include "raymath.h"
|
||||||
|
|
||||||
|
#include "keys.h"
|
||||||
|
#include "bullet.h"
|
||||||
|
|
||||||
|
Texture minigun_texture;
|
||||||
|
|
||||||
|
void load_minigun()
|
||||||
|
{
|
||||||
|
minigun_texture = LoadTexture("data/minigun.png");
|
||||||
|
}
|
||||||
|
|
||||||
|
float minigun_radius()
|
||||||
|
{
|
||||||
|
return fmax(minigun_texture.width, minigun_texture.height)/2;
|
||||||
|
}
|
||||||
|
|
||||||
|
void draw_minigun(Vector2 pos, Camera2D *cam)
|
||||||
|
{
|
||||||
|
|
||||||
|
Texture m = minigun_texture;
|
||||||
|
Rectangle source = {0, 0, m.width, m.height};
|
||||||
|
Rectangle dest = {pos.x, pos.y, m.width, m.height};
|
||||||
|
Vector2 origin = {m.width/2, m.height/2};
|
||||||
|
float angle = -Vector2LineAngle(pos, GetMousePosition());
|
||||||
|
angle *= 180/PI;
|
||||||
|
|
||||||
|
if (key_down(KC_SHOOT)) {
|
||||||
|
bullet_spawn(BULLET_MINIGUN, GetScreenToWorld2D(pos, *cam), angle);
|
||||||
|
|
||||||
|
int speed = 5;
|
||||||
|
Vector2 toward = Vector2Normalize((Vector2) {cos(angle * PI/180), sin(angle * PI/180)});
|
||||||
|
cam->target = Vector2Subtract(GetScreenToWorld2D(pos, *cam), Vector2Scale(toward, speed));
|
||||||
|
}
|
||||||
|
|
||||||
|
DrawTexturePro(m, source, dest, origin, angle + 90, WHITE);
|
||||||
|
}
|
Loading…
Reference in New Issue