Permalink
Browse files

Small update. Bullet needs re-work

  • Loading branch information...
Zielak committed Oct 21, 2015
1 parent d5abb7c commit 47a9c6a9ab6f3baecadb845cdfcf3f3187414988
Showing with 26 additions and 40 deletions.
  1. +1 −1 project.flow
  2. +2 −18 src/Bullet.hx
  3. +13 −11 src/components/Movement.hx
  4. +10 −10 src/components/Shooting.hx
@@ -2,7 +2,7 @@

project : {
name : 'Dodger',
version : '1.0.0',
version : '1.0.1',
author : 'Darek Greenly',

app : {
@@ -3,25 +3,16 @@ package ;

import luxe.collision.shapes.Circle;
import luxe.Rectangle;
import luxe.Visual;
import luxe.Sprite;

import phoenix.Vector;

import components.Movement;
import components.Collider;

typedef BulletOptions = {
@:optional var yspeed:Float;
@:optional var xspeed:Float;
}

class Bullet extends Visual
class Bullet extends Sprite
{
public static inline var BULLET_R:Float = 5;

public var bulletoptions:BulletOptions;

var movement:Movement;
var collider:Collider;


@@ -33,13 +24,6 @@ class Bullet extends Visual
collider.testAgainst = 'enemy';
collider.shape = new Circle(0, 0, BULLET_R);

movement = new Movement({name:'movement'});
movement.yspeed = (bulletoptions.yspeed!=null) ? bulletoptions.yspeed : 0;
movement.xspeed = (bulletoptions.xspeed!=null) ? bulletoptions.xspeed : 0;
movement.bounds = new Rectangle(0, -10, Luxe.screen.w, Luxe.screen.h);
movement.killBounds = new Rectangle(-10, 0, Luxe.screen.w+10, Luxe.screen.h+10);

add(movement);
add(collider);
}

@@ -25,22 +25,24 @@ class Movement extends Component

override function onfixedupdate(rate:Float):Void
{
pos.x += xspeed * rate;
pos.y += yspeed * rate;
trace('movement.onfixedupdate( )');

if(pos.x > killBounds.w
|| pos.x < killBounds.x
|| pos.y > killBounds.h
|| pos.y < killBounds.y)
entity.pos.x += xspeed * rate;
entity.pos.y += yspeed * rate;

if(entity.pos.x > killBounds.w
|| entity.pos.x < killBounds.x
|| entity.pos.y > killBounds.h
|| entity.pos.y < killBounds.y)
{
// trace('OUT OF SCENE trying to destroy myself ${pos}');
// trace('OUT OF SCENE trying to destroy myself ${entity.pos}');
entity.destroy(true);
}

if(pos.x > bounds.w) pos.x = bounds.w;
if(pos.x < bounds.x) pos.x = bounds.x;
if(pos.y > bounds.h) pos.y = bounds.h;
if(pos.y < bounds.y) pos.y = bounds.y;
if(entity.pos.x > bounds.w) entity.pos.x = bounds.w;
if(entity.pos.x < bounds.x) entity.pos.x = bounds.x;
if(entity.pos.y > bounds.h) entity.pos.y = bounds.h;
if(entity.pos.y < bounds.y) entity.pos.y = bounds.y;

}

@@ -4,6 +4,7 @@ package components;
import Bullet;

import luxe.Component;
import luxe.Rectangle;
import phoenix.Color;
import phoenix.Vector;

@@ -19,8 +20,6 @@ class Shooting extends Component
public var bulletspeed:Float = 600;


var bullet:Bullet;

var _input:Input;

override function init():Void
@@ -56,19 +55,20 @@ class Shooting extends Component
// trace('shooting FIRE()');
cooldown = maxcooldown;

bullet = new Bullet({
var bullet = new Bullet({
name: 'bullet',
name_unique: true,
pos: new Vector().copy_from(entity.pos),
color: new Color().rgb(0xFFFFAA),
geometry: Luxe.draw.circle({
x: 0, y: 0,
r: Bullet.BULLET_R
})
size: new Vector(Bullet.BULLET_R, Bullet.BULLET_R),
});
bullet.bulletoptions = {
yspeed: -bulletspeed
};

var movement = new Movement({name:'movement'});
movement.yspeed = -bulletspeed;
movement.xspeed = 0;
movement.bounds = new Rectangle(0, -10, Luxe.screen.w, Luxe.screen.h);
movement.killBounds = new Rectangle(-10, 0, Luxe.screen.w+10, Luxe.screen.h+10);
bullet.add( movement );
}


0 comments on commit 47a9c6a

Please sign in to comment.