Skip to content

Commit

Permalink
energy emitter and energy pickup
Browse files Browse the repository at this point in the history
  • Loading branch information
leafo committed Dec 16, 2012
1 parent 5f5e89d commit 0a079bc
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 8 deletions.
30 changes: 30 additions & 0 deletions particles.moon
Expand Up @@ -53,6 +53,36 @@ class SparkEmitter extends Emitter
new: (world, x,y, @dir) =>
super world, x,y


class EnergyEmitter extends Emitter
P = class extends Particle
life: 0.5
ox: 3
oy: 3
sprite: "117,20,7,7"

new: (...) =>
@rot = random! * math.pi / 2
super ...

update: (dt, ...) =>
dampen_vector @vel, dt * 200
super dt, ...

draw: =>
p = @p!
a = (1 - p) * 255
g.setColor @r, @g, @b, a
sprite\draw @sprite, @x, @y, p * @rot, nil, nil, @ox, @oy

new: (world, x, y) =>
super world, x, y, 0.1, 10

make_particle: (x,y) =>
rads = random! * math.pi * 2
P x,y, Vec2d.from_radians(rads) * 100


class Explosion extends Sequence
alive: true

Expand Down
33 changes: 26 additions & 7 deletions pickup.moon
Expand Up @@ -19,6 +19,11 @@ class Energy extends Box

super x,y, @size, @size

on_collect: (world) =>
world.particles\add EnergyEmitter world, @center!
world.energy_count += 1
@alive = false

update: (dt) =>
if @gravity_parent
{:x,:y} = @gravity_parent
Expand All @@ -43,17 +48,31 @@ class Energy extends Box
draw: =>
half = @size/2
sprite\draw @sprite, @x + half, @y + half, @rot, nil, nil, @ox, @oy

-- g.setColor 255,100,100 if @gravity_parent
-- g.rectangle "line", @unpack!
-- g.setColor 255,255,255

-- gravitate: (dt, pt, radius) =>
-- to_thing = pt - Vec2d @center!
-- p = to_thing\len! / radius
-- return if p > 1
__tostring: => "Energy<>"

-- @accel = to_thing\normalized! * (p - 0.2) * 500

__tostring: => "Energy<>"
class BombPad extends Box
w: 48
h: 32

seq: {
"160,96,48,32",
"160,128,48,32",
}

new: (@x, @y) =>
@anim = sprite\seq @seq, 0.5

draw: => @anim\draw @x, @y

update: (dt, world) =>
@anim\update dt
if world.viewport\touches_box @
for e in *world.collide\get_touching @
if e.is_energy and e.alive
e\on_collect world

2 changes: 1 addition & 1 deletion tank.moon
Expand Up @@ -134,7 +134,7 @@ class Player extends Tank
if @sucking = keyboard.isDown " "
radius = @suck_radius_box!
for e in *world.collide\get_touching radius
if e.is_energy and not e.gravity_parent
if e.is_energy and and e.alive and not e.gravity_parent
table.insert @held_energy, e
e.gravity_parent = @
else
Expand Down

0 comments on commit 0a079bc

Please sign in to comment.