51 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
			
		
		
	
	
			51 lines
		
	
	
		
			1.7 KiB
		
	
	
	
		
			C
		
	
	
	
	
	
//    Copyright 2025 Bill Rossi
 | 
						|
//    
 | 
						|
//    This file is part of Starship Futuretime
 | 
						|
//
 | 
						|
//    Starship Futuretime is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
 | 
						|
//
 | 
						|
//    Starship Futuretime is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
 | 
						|
//
 | 
						|
//    You should have received a copy of the GNU General Public License along with Starship Futuretime. If not, see <https://www.gnu.org/licenses/>. 
 | 
						|
#include <stdlib.h>
 | 
						|
 | 
						|
#include <raylib.h>
 | 
						|
 | 
						|
#include "bullet.h"
 | 
						|
#include "entity.h"
 | 
						|
 | 
						|
Entity *spawn_bullet(Vector2 spawn_at, bool from_enemy) {
 | 
						|
  Entity *e = malloc(sizeof(Entity));
 | 
						|
  e->name = "Bullet";
 | 
						|
  e->properties = malloc(sizeof(Entity));
 | 
						|
  e->timer = 0.5;
 | 
						|
  BulletProperties *props = (BulletProperties*)e->properties;
 | 
						|
  props->position.x = spawn_at.x;
 | 
						|
  props->position.y = spawn_at.y;
 | 
						|
  props->position.width = 4;
 | 
						|
  props->position.height = 10;
 | 
						|
  props->velocity.x = 0;
 | 
						|
  props->velocity.y = from_enemy ? 10 : -10;
 | 
						|
  props->from_enemy = from_enemy;
 | 
						|
  e->draw = &draw_bullet;
 | 
						|
  e->tick = &tick_bullet;
 | 
						|
  e->free = &free_bullet;
 | 
						|
  return e;
 | 
						|
}
 | 
						|
 | 
						|
void draw_bullet(Entity *e) {
 | 
						|
  BulletProperties *props = e->properties;
 | 
						|
  DrawRectangleRec(props->position, props->from_enemy ? RED : BLACK);
 | 
						|
}
 | 
						|
 | 
						|
void tick_bullet(Game *g, Entity *e, float dt) {
 | 
						|
  BulletProperties *props = e->properties;
 | 
						|
  e->timer -= dt;
 | 
						|
  props->position.y += props->velocity.y;
 | 
						|
}
 | 
						|
 | 
						|
void free_bullet(Entity *e) {
 | 
						|
  free(e->properties);
 | 
						|
  free(e);
 | 
						|
}
 |