Skip to content

Commit

Permalink
Rock spitting, constrain to screen
Browse files Browse the repository at this point in the history
  • Loading branch information
Draknek committed May 1, 2011
1 parent 74539e9 commit 4a0518c
Show file tree
Hide file tree
Showing 9 changed files with 425 additions and 26 deletions.
29 changes: 23 additions & 6 deletions Creature.as
Original file line number Diff line number Diff line change
Expand Up @@ -30,33 +30,48 @@ package

public var hurtBy:Array;

public function Creature (_x:Number = 0, _y:Number = 0)
public function Creature (_x:int = 0, _y:int = 0)
{
x = _x;
y = _y;
}

public function nativeBehaviour (): void
{
const TIMER:int = 32;

if (moveTimer == 0) {
doAction1 = (FP.rand(10) == 0);

var r:int = FP.rand(6);

if (r != 0) { // r == 0: keep going in same direction
inputDX = 0;
inputDY = 0;

if (r == 1) inputDX = 1;
else if (r == 2) inputDX = -1;
else if (r == 3) inputDY = 1;
else if (r == 4) inputDY = -1;

inputDX *= 0.5;
inputDY *= 0.5;
}

moveTimer = 16*2;
const BOUNDS:int = 16;

var cx:Number = x+inputDX*TIMER - world.camera.x;
var cy:Number = y+inputDY*TIMER - world.camera.y;

if (cx < BOUNDS || cx > Room.WIDTH - BOUNDS) {
inputDX *= -1;
}

if (cy < BOUNDS || cy > Room.HEIGHT - BOUNDS) {
inputDY *= -1;
}

moveTimer = TIMER;
}

moveTimer--;
Expand Down Expand Up @@ -112,7 +127,7 @@ package
complete: function ():void
{
if (c.isPlayer) {
Level(world).player = nextHost;
Room(world).player = nextHost;
nextHost.isPlayer = true;
nextHost.active = true;
}
Expand Down Expand Up @@ -195,6 +210,8 @@ package
else if (dy) straighten("x");
}

trace(dx+", "+dy);

isMoving = (dx || dy);
doMovement();

Expand Down
22 changes: 19 additions & 3 deletions Leever.as
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ package
public var sprite:Spritemap;

public var undergrounding:Boolean = false;
public var underground:Boolean = false;
public var switching:Boolean = false;

public function Leever (_x:Number = 0, _y:Number = 0)
Expand All @@ -36,12 +37,21 @@ package

public override function doMovement (): void
{
moveBy(dx, dy, "leever_solid");
var solidTypes:Array = ["leever_solid"];

collidable = true;
sprite.visible = true;
if (! underground) {
solidTypes.push("leever", "solid");
}

moveBy(dx, dy, solidTypes);

if (underground) {
solidTypes.push("leever", "solid");
}

if (doAction1) {
if (underground && collideTypes(solidTypes, x, y)) return;

switching = true;

if (sprite.complete || (sprite.currentAnim != "buried" && sprite.currentAnim != "halfway")) {
Expand All @@ -51,10 +61,16 @@ package

undergrounding = ! undergrounding;
} else if (sprite.complete) {

collidable = true;
sprite.visible = true;
underground = false;

if (undergrounding) {
if (sprite.currentAnim == "buried") {
sprite.visible = false;
collidable = false;
underground = true;
}
else if (sprite.currentAnim == "halfway") sprite.play("buried");
} else {
Expand Down
12 changes: 2 additions & 10 deletions Level.as
Original file line number Diff line number Diff line change
Expand Up @@ -47,20 +47,12 @@ package

public function Level ()
{
tiles = new Tilemap(TilesGfx, WORLD_WIDTH, WORLD_HEIGHT, 16, 16);
tiles = Overworld.tiles.getSubMap(0, 0, 16, 10);

//tiles.setRect(0, 0, tiles.columns, tiles.rows, ROCK);

//tiles.setRect(1, 1, tiles.columns - 2, tiles.rows - 2, GRASS);

tiles.loadFromString(new MapData);

tiles.setRect(7, 4, 2, 2, SAND);
calculateMasks();

addGraphic(tiles);

reloadData();

player = new Octorok(FP.width*0.5, FP.height*0.5);

player.isPlayer = true;
Expand Down
12 changes: 7 additions & 5 deletions Main.as
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ package
{
public function Main ()
{
super(256*2, 160*2, 60, true);
super(256, 160, 60, true);
FP.screen.scale = 2;
//FP.console.enable();
FP.console.enable();

Input.define("ACTION1", Key.Z, Key.X, Key.C, Key.SPACE, Key.ENTER);
Input.define("ACTION2");
Expand All @@ -21,10 +21,12 @@ package

super.init();

FP.width *= 0.5;
FP.height *= 0.5;
//FP.width *= 0.5;
//FP.height *= 0.5;

FP.world = new Level();
Overworld.init();

FP.world = new Room(0, 0);
}

public function sitelock (allowed:*):Boolean
Expand Down
4 changes: 2 additions & 2 deletions Octorok.as
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ package

type = "octorok";

hurtBy = ["leever", "octorok"];
hurtBy = ["leever"];
}

public override function doMovement (): void
{
moveBy(dx, dy, "octorok_solid");
moveBy(dx, dy, ["octorok_solid"]);//, "octorok"]);

if (isMoving) {
walkSprite.angle = angle;
Expand Down
113 changes: 113 additions & 0 deletions Overworld.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
package
{
import net.flashpunk.*;
import net.flashpunk.graphics.*;
import net.flashpunk.masks.*;
import net.flashpunk.utils.*;
import flash.utils.ByteArray;

public class Overworld
{
[Embed(source="images/tiles.png")] public static const TilesGfx: Class;

[Embed(source="map.lvl", mimeType="application/octet-stream")] public static const MapData: Class;

public static var tiles:Tilemap;

public static const WIDTH:int = 512 - 16;
public static const HEIGHT:int = 320 - 16;

public static function init ():void
{
tiles = new Tilemap(TilesGfx, WIDTH, HEIGHT, 16, 16);

tiles.loadFromString(new MapData);

reloadData();
}

public static function reloadData ():void
{
drawEdges();
}

public static function drawEdges ():void
{
tiles.updateAll();

var i:int, j:int;
var a:uint, b:uint, c:uint;

tiles.usePositions = true;

for (i = 0; i < WIDTH; i += 1) {
for (j = 16; j < HEIGHT; j += 16) {
a = tiles.getTile(i, j - 1);
b = tiles.getTile(i, j);

if (a == b) continue;

tiles.setPixel(i, j - FP.rand(2), Room.BLACK);

var d:int = tileDiff(a, b);

if (d) {
c = color(a, b, d);

d -= FP.rand(2);

//c = FP.colorLerp(Room.BLACK, tiles.getPixel(i, j + d), 0.25);

tiles.setPixel(i, j + d, c);
}
}
}

for (i = 16; i < WIDTH; i += 16) {
for (j = 0; j < HEIGHT; j += 1) {
a = tiles.getTile(i - 1, j);
b = tiles.getTile(i, j);

if (a == b) continue;

tiles.setPixel(i - FP.rand(2), j, Room.BLACK);

d = tileDiff(a, b);

if (d) {
c = color(a, b, d);

d -= FP.rand(2);

//c = FP.colorLerp(Room.BLACK, tiles.getPixel(i, j + d), 0.25);

tiles.setPixel(i + d, j, c);
}
}
}

tiles.usePositions = false;
}

private static function tileDiff (a:uint, b:uint): int
{
if (a == Room.WATER) return 2;
if (b == Room.WATER) return -2;
if (a == Room.ROCK) return -3;
if (b == Room.ROCK) return 3;
return 0;
}

private static function color (a:uint, b:uint, diff:int): uint
{
var tile:uint = (diff > 0) ? b : a;

if (tile == Room.ROCK) return Room.BLACK;
if (tile == Room.GRASS) return 0xff265f49;

return Room.BLACK;
}

}
}

73 changes: 73 additions & 0 deletions RockSpit.as
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
package
{
import net.flashpunk.*;
import net.flashpunk.graphics.*;
import net.flashpunk.masks.*;
import net.flashpunk.utils.*;

import flash.display.*;

public class RockSpit extends Entity
{
[Embed(source="images/rockspit.png")] public static const RockGfx: Class;

public var vx:Number = 0;
public var vy:Number = 0;

public var owner:Octorok = null;

public function RockSpit (_x:Number, _y:Number, _vx:Number, _vy:Number, _owner:Octorok)
{
super(_x, _y);

vx = _vx;
vy = _vy;

owner = _owner;

graphic = new Stamp(RockGfx, -8, -8);

setHitbox(6, 6, 3, 3);

type = "octorok_spit";
}

public override function update ():void
{
x += vx;
y += vy;

if (collide("projectile_solid", x, y)) {
world.remove(this);
}

if (! onCamera) {
visible = false;
world.remove(this);
}
}

public override function removed ():void
{
if (! visible) return;

var e:Emitter = new Emitter(foo, 2, 2);
e.newType("a");
e.setMotion("a", 0, 10, 15, 360, 5, 10);
e.setAlpha("a");
e.emit("a", x, y);
e.emit("a", x, y);
e.emit("a", x, y);
e.emit("a", x, y);
e.emit("a", x, y);
e.emit("a", x, y);
e.emit("a", x, y);
e.emit("a", x, y);
e.emit("a", x, y);
FP.world.addGraphic(e);
}

public static const foo:BitmapData = new BitmapData(2, 2, false, 0x4e5159);
}
}

Loading

0 comments on commit 4a0518c

Please sign in to comment.