Skip to content

Commit

Permalink
tapes transport player across room
Browse files Browse the repository at this point in the history
  • Loading branch information
Aurel300 committed Feb 24, 2018
1 parent 6b5bf35 commit ebd843e
Show file tree
Hide file tree
Showing 7 changed files with 62 additions and 18 deletions.
7 changes: 2 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ ROGUELIKE
- [ ] player
- [.] animate dis/appearance
- [ ] shadow
- [ ] piece of tape for corridors
- [x] piece of tape for corridors
- gameplay
- [ ] room generation
- [x] generate macro-grid
Expand All @@ -84,10 +84,7 @@ ROGUELIKE
- [ ] text justify
- [ ] mark words - words become enemies / censored
- [ ] controls
- [.] moving around
- [x] speed limit
- [x] collision
- [ ] other rooms
- [x] moving around
- [ ] shooting?
- [x] vision cone
- [x] left click to see
Expand Down
14 changes: 14 additions & 0 deletions lib/Entity.hx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ class Entity {

}

public function moveTo(to:RoomState, tx:Int, ty:Int):Void {
room.entities.remove(this);
room = to;
room.entities.push(this);
x = tx;
y = ty;
}

public inline function walkOrtho(ox:Int, oy:Int):Bool {
return walk(ox, ox != 0 ? 0 : oy);
}
Expand All @@ -28,6 +36,12 @@ class Entity {
var nx = x + ox;
var ny = y + oy;
if (!nx.withinI(0, room.w2 - 1) || !ny.withinI(0, room.h2 - 1)) return false;
for (p in room.portals) {
if (nx == p.fx && ny == p.fy) {
moveTo(p.to, p.tx, p.ty);
return true;
}
}
switch (room.walls[room.indexTile(nx, ny)]) {
case Solid: return false;
case _:
Expand Down
1 change: 1 addition & 0 deletions lib/Player.hx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ class Player extends Entity {
}

override public function tick(state:GameState):Void {
room.visited = true;
if (cdWalk == 0) {
if (walkOrtho(
(1).negposI(state.keys.left, state.keys.right)
Expand Down
9 changes: 9 additions & 0 deletions lib/Portal.hx
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package lib;

typedef Portal = {
to:RoomState
,fx:Int
,fy:Int
,tx:Int
,ty:Int
};
35 changes: 26 additions & 9 deletions lib/Procgen.hx
Original file line number Diff line number Diff line change
Expand Up @@ -85,9 +85,8 @@ class Procgen {
var h = minSide + ((minSide >> 1) - varSide);
var grid = [ for (y in 0...h) for (x in 0...w) -1 ];
inline function idx(x:Int, y:Int) return x + y * w;
var initial = 4; //idx(FM.prng.nextMod(w), FM.prng.nextMod(h));
var initial = idx(FM.prng.nextMod(w), FM.prng.nextMod(h));
grid[initial] = 0;
trace(w, h, initial);
var order = [ for (r in 1...roomCount) {
var pos = [];
var gi = 0;
Expand All @@ -107,11 +106,10 @@ class Procgen {
gi++;
}
var nxt = FM.prng.nextElement(pos);
trace(nxt);
grid[nxt.pos] = r;
{at: nxt.pos, from: FM.prng.nextElement([ for (k in nxt.from.keys()) if (nxt.from[k]) k ])};
{at: nxt.pos, r: r, from: FM.prng.nextElement([ for (k in nxt.from.keys()) if (nxt.from[k]) k ])};
} ];
order.unshift({at: initial, from: -1});
order.unshift({at: initial, r: 0, from: -1});
var storyIndices = [ for (i in 0...roomCount) i ];
while (storyIndices.length > storyRooms) {
storyIndices.splice(FM.prng.nextMod(storyIndices.length), 1);
Expand All @@ -126,6 +124,7 @@ class Procgen {
var nx = n.at % w;
var ny = (n.at / w).floor();
var rstate = createRoom(storyIndices.indexOf(n.at) != -1 ? Clipping : Normal, story);
rstate.title = '${n.r + 1}';
gridStates[n.at] = rstate;
maxW[nx] = maxW[nx].maxI(rstate.width);
maxH[ny] = maxH[ny].maxI(rstate.height);
Expand All @@ -139,39 +138,57 @@ class Procgen {
var colY = [ for (y in 1...h) colRy += maxH[y - 1] ];
colX.unshift(0);
colY.unshift(0);
trace(colX, colY);
for (s in states) {
var fox = 0;
var foy = 0;
if (s.from != -1) {
var sfx = s.from % w;
var sfy = (s.from / w).floor();
fox = s.x - sfx;
foy = s.y - sfy;
var tape = new Tape(gridStates[s.from], s.state);
tape.vertical = sfx == s.x;
trace(tape.vertical);
if (tape.vertical) {
function portY(s1:RoomState, s2:RoomState, x:Int, y1:Int, y2:Int, s1h:Bool):Void {
s1.portals.push({to: s2, fx: x, fy: y1, tx: x, ty: y2 + (s1h ? 1 : -1)});
s1.portals.push({to: s2, fx: x + 1, fy: y1, tx: x + 1, ty: y2 + (s1h ? 1 : -1)});
s2.portals.push({to: s1, fx: x, fy: y2, tx: x, ty: y1 + (s1h ? -1 : 1)});
s2.portals.push({to: s1, fx: x + 1, fy: y2, tx: x + 1, ty: y1 + (s1h ? -1 : 1)});
}
tape.fromX = 1 + FM.prng.nextMod(minW[s.x] * 2 - 4);
if (s.from < s.at) {
tape.fromY = gridStates[s.from].height * 2 - 3;
tape.length = 6 + (maxH[sfy] - gridStates[s.from].height) * 2;
portY(gridStates[s.from], s.state, tape.fromX + 1, tape.fromY + 1, 1, true);
} else {
tape.fromY = 1;
tape.length = -(6 + (maxH[s.y] - s.state.height) * 2);
portY(gridStates[s.from], s.state, tape.fromX + 1, 1, s.state.h2 - 2, false);
}
} else {
function portX(s1:RoomState, s2:RoomState, y:Int, x1:Int, x2:Int, s1l:Bool):Void {
s1.portals.push({to: s2, fy: y, fx: x1, ty: y, tx: x2 + (s1l ? 1 : -1)});
s1.portals.push({to: s2, fy: y + 1, fx: x1, ty: y + 1, tx: x2 + (s1l ? 1 : -1)});
s2.portals.push({to: s1, fy: y, fx: x2, ty: y, tx: x1 + (s1l ? -1 : 1)});
s2.portals.push({to: s1, fy: y + 1, fx: x2, ty: y + 1, tx: x1 + (s1l ? -1 : 1)});
}
tape.fromY = 1 + FM.prng.nextMod(minH[s.y] * 2 - 4);
if (s.from < s.at) {
tape.fromX = gridStates[s.from].width * 2 - 3;
tape.length = 6 + (maxW[sfx] - gridStates[s.from].width) * 2;
portX(gridStates[s.from], s.state, tape.fromY + 1, tape.fromX + 1, 1, true);
} else {
tape.fromX = 1;
tape.length = -(6 + (maxW[s.x] - s.state.width) * 2);
portX(gridStates[s.from], s.state, tape.fromY + 1, 1, s.state.w2 - 2, false);
}
}
gridStates[s.from].tapes.push(tape);
}
ret.rooms.push({
state: s.state
,x: colX[s.x] * Renderer.ROOM_SIZE
,y: colY[s.y] * Renderer.ROOM_SIZE
,x: colX[s.x] * Renderer.ROOM_SIZE + fox * Main.W
,y: colY[s.y] * Renderer.ROOM_SIZE + foy * Main.H
,z: 0
,tx: colX[s.x] * Renderer.ROOM_SIZE
,ty: colY[s.y] * Renderer.ROOM_SIZE
Expand Down
12 changes: 8 additions & 4 deletions lib/Renderer.hx
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,9 @@ class Renderer {
state.layout.rooms.map(renderRoom.bind(_, state, ab));
for (l in state.layout.rooms) {
for (t in l.state.tapes) {
if (t.from == l.state) renderTape(t, l, ab);
if (t.from == l.state && (t.from.visited || t.to.visited)) {
renderTape(t, l, ab);
}
}
}
}
Expand Down Expand Up @@ -197,9 +199,11 @@ class Renderer {
}
}
}
room.x.target(room.tx, 19);
room.y.target(room.ty, 19);
room.z.target(room.tz, 29);
if (room.state.visited) {
room.x.target(room.tx, 19);
room.y.target(room.ty, 19);
room.z.target(room.tz, 29);
}
var rx = room.x.floor() - camX.floor();
var ry = room.y.floor() - room.z.floor() - camY.floor();
if (rx < Main.W && ry < Main.H
Expand Down
2 changes: 2 additions & 0 deletions lib/RoomState.hx
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ class RoomState {
static inline var POV_STRENGTH:Float = 100;

public var id:Int;
public var visited:Bool = false;
public var width:Int;
public var height:Int;
public var w2:Int;
Expand All @@ -21,6 +22,7 @@ class RoomState {
public var title:String;
public var boundary:Vector<Point2DI>;
public var tapes:Array<Tape> = [];
public var portals:Array<Portal> = [];

public function new(type:RoomType, width:Int, height:Int) {
this.type = type;
Expand Down

0 comments on commit ebd843e

Please sign in to comment.