Compare commits
No commits in common. "6e45a0ce118438f8c865c6cb25cb4876b640db10" and "2f1fc1e4ae45b7e53b3166fec25dda59981030c3" have entirely different histories.
6e45a0ce11
...
2f1fc1e4ae
2
Makefile
2
Makefile
|
@ -1,4 +1,4 @@
|
||||||
SRC=main.c ninja.c keys.c bullet.c
|
SRC=main.c ninja.c keys.c
|
||||||
EXE=voleur
|
EXE=voleur
|
||||||
CC=gcc
|
CC=gcc
|
||||||
|
|
||||||
|
|
52
bullet.c
52
bullet.c
|
@ -1,52 +0,0 @@
|
||||||
#include <stdio.h>
|
|
||||||
#include "raylib.h"
|
|
||||||
#include "raymath.h"
|
|
||||||
|
|
||||||
#include "bullet.h"
|
|
||||||
|
|
||||||
typedef struct Bullet {
|
|
||||||
BulletType type;
|
|
||||||
Vector2 pos;
|
|
||||||
float time;
|
|
||||||
float angle;
|
|
||||||
} Bullet;
|
|
||||||
|
|
||||||
#define BULLET_MAX 500
|
|
||||||
|
|
||||||
Bullet bullets[BULLET_MAX] = {0};
|
|
||||||
|
|
||||||
Texture textures[BULLET_COUNT];
|
|
||||||
|
|
||||||
void bullet_load()
|
|
||||||
{
|
|
||||||
textures[BULLET_SHURIKEN] = LoadTexture("data/shuriken.png");
|
|
||||||
}
|
|
||||||
|
|
||||||
void bullet_spawn(BulletType type, Vector2 pos, float angle)
|
|
||||||
{
|
|
||||||
for (int i = 0; i < BULLET_MAX; i++) {
|
|
||||||
if (bullets[i].time >= EPSILON)
|
|
||||||
continue;
|
|
||||||
bullets[i].time = 5;
|
|
||||||
bullets[i].angle = angle;
|
|
||||||
bullets[i].pos.x = pos.x - textures[type].width/2;
|
|
||||||
bullets[i].pos.y = pos.y - textures[type].height/2;
|
|
||||||
bullets[i].type = type;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void draw_bullets()
|
|
||||||
{
|
|
||||||
for (int i = 0; i < BULLET_MAX; i++) {
|
|
||||||
if (bullets[i].time <= EPSILON)
|
|
||||||
continue;
|
|
||||||
|
|
||||||
float speed = 50;
|
|
||||||
float angle = bullets[i].angle * PI/180;
|
|
||||||
Vector2 toward = Vector2Normalize((Vector2) {cos(angle), sin(angle)});
|
|
||||||
bullets[i].pos = Vector2Add(bullets[i].pos, Vector2Scale(toward, speed));
|
|
||||||
bullets[i].time -= GetFrameTime();
|
|
||||||
DrawTexture(textures[bullets[i].type], bullets[i].pos.x, bullets[i].pos.y, WHITE);
|
|
||||||
}
|
|
||||||
}
|
|
15
bullet.h
15
bullet.h
|
@ -1,15 +0,0 @@
|
||||||
#ifndef BULLET_H
|
|
||||||
#define BULLET_H
|
|
||||||
|
|
||||||
typedef enum BulletType {
|
|
||||||
BULLET_SHURIKEN,
|
|
||||||
BULLET_COUNT,
|
|
||||||
} BulletType;
|
|
||||||
|
|
||||||
void bullet_load();
|
|
||||||
|
|
||||||
void bullet_spawn(BulletType type, Vector2 pos, float angle);
|
|
||||||
|
|
||||||
void draw_bullets();
|
|
||||||
|
|
||||||
#endif // BULLET_H
|
|
Binary file not shown.
Binary file not shown.
Before Width: | Height: | Size: 400 B |
Binary file not shown.
Before Width: | Height: | Size: 400 B |
3
main.c
3
main.c
|
@ -3,7 +3,6 @@
|
||||||
#include "raylib.h"
|
#include "raylib.h"
|
||||||
#include "raymath.h"
|
#include "raymath.h"
|
||||||
|
|
||||||
#include "bullet.h"
|
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
#include "ninja.h"
|
#include "ninja.h"
|
||||||
|
|
||||||
|
@ -71,7 +70,6 @@ int main(void)
|
||||||
change_layout_azerty();
|
change_layout_azerty();
|
||||||
|
|
||||||
load_ninja();
|
load_ninja();
|
||||||
bullet_load();
|
|
||||||
|
|
||||||
while (!WindowShouldClose()) {
|
while (!WindowShouldClose()) {
|
||||||
float DT = GetFrameTime();
|
float DT = GetFrameTime();
|
||||||
|
@ -111,7 +109,6 @@ int main(void)
|
||||||
BeginMode2D(effect_camera);
|
BeginMode2D(effect_camera);
|
||||||
{
|
{
|
||||||
DrawTexture(map.texture, map.box.x, map.box.y, WHITE);
|
DrawTexture(map.texture, map.box.x, map.box.y, WHITE);
|
||||||
draw_bullets();
|
|
||||||
}
|
}
|
||||||
EndMode2D();
|
EndMode2D();
|
||||||
draw_ninja(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera);
|
draw_ninja(Vector2Add(SCREEN_MIDDLE, cam_shake), &camera);
|
||||||
|
|
14
ninja.c
14
ninja.c
|
@ -3,15 +3,12 @@
|
||||||
#include "stdio.h"
|
#include "stdio.h"
|
||||||
|
|
||||||
#include "keys.h"
|
#include "keys.h"
|
||||||
#include "bullet.h"
|
|
||||||
|
|
||||||
Texture ninja_texture;
|
Texture ninja_texture;
|
||||||
Texture ninja_attack_texture;
|
Texture ninja_attack_texture;
|
||||||
|
|
||||||
float dash_time = 0;
|
float dash_time = 0;
|
||||||
|
|
||||||
float main_attack_cooldown = 0;
|
|
||||||
|
|
||||||
void load_ninja()
|
void load_ninja()
|
||||||
{
|
{
|
||||||
ninja_texture = LoadTexture("data/ninja.png");
|
ninja_texture = LoadTexture("data/ninja.png");
|
||||||
|
@ -29,8 +26,7 @@ Vector2 ninja_dash(Vector2 pos, Vector2 to, float sec)
|
||||||
Vector2 dash = {0};
|
Vector2 dash = {0};
|
||||||
if (sec <= EPSILON)
|
if (sec <= EPSILON)
|
||||||
return dash;
|
return dash;
|
||||||
if (main_attack_cooldown <= EPSILON && key_pressed(KC_SHOOT)) {
|
if (key_pressed(KC_SHOOT)) {
|
||||||
main_attack_cooldown = sec + 0.069;
|
|
||||||
dash_time = sec;
|
dash_time = sec;
|
||||||
Vector2 diff = Vector2Subtract(to, pos);
|
Vector2 diff = Vector2Subtract(to, pos);
|
||||||
Vector2 scale = Vector2Normalize(diff);
|
Vector2 scale = Vector2Normalize(diff);
|
||||||
|
@ -39,14 +35,12 @@ Vector2 ninja_dash(Vector2 pos, Vector2 to, float sec)
|
||||||
scale.y *= dist;
|
scale.y *= dist;
|
||||||
target = Vector2Add(pos, scale);
|
target = Vector2Add(pos, scale);
|
||||||
}
|
}
|
||||||
if (dash_time > EPSILON) {
|
if (dash_time > 0) {
|
||||||
float dt = GetFrameTime();
|
float dt = GetFrameTime();
|
||||||
dash_time -= dt;
|
dash_time -= dt;
|
||||||
dash.x = Lerp(pos.x, target.x, dt/sec) - pos.x;
|
dash.x = Lerp(pos.x, target.x, dt/sec) - pos.x;
|
||||||
dash.y = Lerp(pos.y, target.y, dt/sec) - pos.y;
|
dash.y = Lerp(pos.y, target.y, dt/sec) - pos.y;
|
||||||
}
|
}
|
||||||
if (main_attack_cooldown > EPSILON)
|
|
||||||
main_attack_cooldown -= GetFrameTime();
|
|
||||||
return dash;
|
return dash;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -97,10 +91,6 @@ void draw_ninja(Vector2 pos, Camera2D *cam)
|
||||||
float angle = -Vector2LineAngle(pos, GetMousePosition());
|
float angle = -Vector2LineAngle(pos, GetMousePosition());
|
||||||
angle *= 180/PI;
|
angle *= 180/PI;
|
||||||
angle += 90;
|
angle += 90;
|
||||||
|
|
||||||
if (main_attack_cooldown <= EPSILON && key_pressed(KC_SPECIAL))
|
|
||||||
bullet_spawn(BULLET_SHURIKEN, GetScreenToWorld2D(pos, *cam), angle - 90);
|
|
||||||
|
|
||||||
DrawTexturePro(n, source, dest, origin, angle, WHITE);
|
DrawTexturePro(n, source, dest, origin, angle, WHITE);
|
||||||
|
|
||||||
// hit_hitbox(pos, angle);
|
// hit_hitbox(pos, angle);
|
||||||
|
|
Loading…
Reference in New Issue