Oh dear, thanks Steve!
Next time I'll only listen to Monsieur OUXX, when I understand what I write.
Next time I'll only listen to Monsieur OUXX, when I understand what I write.

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.
Show posts MenuQuote
Right now bullets can fly to 0° ,45° to the left 90° left and get stuck but render at 90° to the right.
//here's the bullet struct
struct cBullets {
int x;
int y;
bool active;
float vector_x;
float vector_y;
int speed;
int gravity;
int sprite;
import float Length();
import void Normalize();
};
float cBullets::Length() {
return Maths.Sqrt(this.vector_x * this.vector_x + this.vector_y * this.vector_y);
}
void cBullets::Normalize ()
{
float l = this.Length ();
if ( l == 1.0 || l == 0.0 )
return;
float tmp = 1.0 / l;
this.vector_x = this.vector_x * tmp;
this.vector_y = this.vector_y * tmp;
}
// here's shooting
// TENG.get_free_bullet works fine btw.
static function TENG::shoot_player_bullet()
{
int xpos;
int ypos;
int modifier;
int nextFree;
if (weapon[ego_stats.active_weapon].bullet_sprite >-1) {
nextFree = TENG.get_free_bullet (true);
if (nextFree > -1) {
if (ego_stats.SpriteDirection == 4) {
xpos = player.x + (TENG.get_char_width(player)/2);
modifier = 1;
}
else {
xpos = player.x - (TENG.get_char_width(player)/2);
modifier = -1;
}
ypos = player.y - (TENG.get_char_height(player)/2);
player_bullet[nextFree].x = xpos;
player_bullet[nextFree].y = ypos;
player_bullet[nextFree].speed = weapon[ego_stats.active_weapon].speed * modifier ;
player_bullet[nextFree].sprite = weapon[ego_stats.active_weapon].bullet_sprite;
player_bullet[nextFree].active = true;
if (weapon[ego_stats.active_weapon].type == eWT_Freeway) {
player_bullet[nextFree].vector_x = IntToFloat(mouse.x - player.x);
player_bullet[nextFree].vector_y = IntToFloat(mouse.y - player.y);
player_bullet[nextFree].Normalize();
}
}
}
}
// And here's the drawing, called by rep_exec
static function TENG::draw_bullets()
{
DrawingSurface *surface = Room.GetDrawingSurfaceForBackground();
int counter = 0;
// draw player_bullets
while (counter < MAX_BULLETS) {
if (player_bullet[counter].active) {
player_bullet[counter].x += FloatToInt(player_bullet[counter].vector_x) * weapon[ego_stats.active_weapon].speed;
player_bullet[counter].y += FloatToInt(player_bullet[counter].vector_y) * weapon[ego_stats.active_weapon].speed;
surface.DrawImage(player_bullet[counter].x, player_bullet[counter].y, player_bullet[counter].sprite);
}
counter ++;
}
surface.Release();
}
QuoteI thought you were planning on releasing the source code once it's done.
Quote from: GarageGothic on Tue 27/04/2010 21:13:33
most of what you need could be handled with simple integer maths even for angled shots
Quote
Other optimizations include checking bullets closest to the enemy first, so you don't waste CPU cycles on checking collisions for an enemy that was already destroyed.
By continuing to use this site you agree to the use of cookies. Please visit this page to see exactly how we use these.
Page created in 0.305 seconds with 15 queries.