Skip to content

Commit

Permalink
Small update. Bullet needs re-work
Browse files Browse the repository at this point in the history
  • Loading branch information
Darek Greenly committed Oct 21, 2015
1 parent d5abb7c commit 47a9c6a
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 40 deletions.
2 changes: 1 addition & 1 deletion project.flow
Expand Up @@ -2,7 +2,7 @@

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

app : {
Expand Down
20 changes: 2 additions & 18 deletions src/Bullet.hx
Expand Up @@ -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;


Expand All @@ -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);
}

Expand Down
24 changes: 13 additions & 11 deletions src/components/Movement.hx
Expand Up @@ -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;

}

Expand Down
20 changes: 10 additions & 10 deletions src/components/Shooting.hx
Expand Up @@ -4,6 +4,7 @@ package components;
import Bullet;

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

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


var bullet:Bullet;

var _input:Input;

override function init():Void
Expand Down Expand Up @@ -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 );
}


Expand Down

0 comments on commit 47a9c6a

Please sign in to comment.