Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Comparing changes

Choose two branches to see what's changed or to start a new pull request. If you need to, you can also compare across forks.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also compare across forks.
base fork: lovelyrpgcommunity/A-Whiff-of-Steam
base: dbcdd95b01
...
head fork: lovelyrpgcommunity/A-Whiff-of-Steam
compare: 2d584ed42f
Checking mergeability… Don't worry, you can still create the pull request.
  • 2 commits
  • 3 files changed
  • 0 commit comments
  • 1 contributor
Commits on Feb 27, 2011
@aginiewicz aginiewicz Vectorized some more stuff. Moved character creation to map initializ…
…ation. Added Map.lookAt and Map.lookingAt functions.
9c0a2b9
@aginiewicz aginiewicz Fixed scale a bit 2d584ed
View
7 proto/proto1/character.lua
@@ -41,17 +41,14 @@ function Character:initialize ()
self.direction = "sw"
end
-local CHARACTER_SHIFT = Vector2:new(
- Map.TILE_CENTRE_X,
- IMAGE_HEIGHT-projection.vz.y+Map.TILE_CENTRE_Y
-)
+local CHARACTER_SHIFT = Vector2:new(0,IMAGE_HEIGHT-projection.vz.y)+Map.TILE_CENTRE
function Character:draw (view)
local image = Character.IMAGES[self.image]
local quads = Character.QUADS[self.image]
love.graphics.push()
love.graphics.scale(view.scale)
- local p = projection.worldToView2(self.position,view)-CHARACTER_SHIFT*view.scale
+ local p = projection.worldToView2(self.position,view)/view.scale-CHARACTER_SHIFT
if quads then
local quad = quads[self.direction]
love.graphics.drawq(image, quad, math.floor(p.x), math.floor(p.y))
View
5 proto/proto1/main.lua
@@ -1,12 +1,11 @@
require("map")
require("character")
+local map
+
function love.load (args)
title = love.graphics.getCaption()
map = Map:new()
- character = Character:new()
- map:addCharacter(character)
- character:gotoState('ArrowKeysMovement')
end
function love.update (dt)
View
108 proto/proto1/map.lua
@@ -30,8 +30,10 @@ Map.TILES = {
Map.TILE_WIDTH = projection.vz.x+projection.vx.x
Map.TILE_HEIGHT = projection.vz.y-projection.vx.y
-Map.TILE_CENTRE_X = (projection.vx.x+projection.vz.x)/2
-Map.TILE_CENTRE_Y = (projection.vx.y+projection.vz.y)/2
+Map.TILE_CENTRE = Vector2:new(
+ (projection.vx.x+projection.vz.x)/2,
+ (projection.vx.y+projection.vz.y)/2
+)
Map.MAX_SCALE = 2.0
Map.MIN_SCALE = 0.1
Map.WALK_SPEED = 1
@@ -51,19 +53,46 @@ Map.IMAGES = {
function Map:initialize ()
self.view = {}
- self.size = {width=21, length=21}
- self.view.position = Vector2:new(-350, 350)
+ self.view.position = Vector2:new(0,0)
+ self.view.scale = 1
+ self.size = {width=#Map.TILES[1], length=#Map.TILES}
+ self:lookAt3(self.size.width/2,self.size.length/2)
self.velocity = Vector2:new(0, 0)
self.displayControls = true
self.editorEnabled = false
self.canDrag = false
self.mdp = nil -- mouse down position
- self.view.scale = 1
- self.selectedTile = {x=1, y=1}
+ self.selectedTile = {
+ x=math.floor(self.size.width/2)+1,
+ y=math.floor(self.size.length/2)+1
+ }
+ self.character = Character:new()
+ self.character:gotoState('ArrowKeysMovement')
+end
+
+function Map:lookAt(w)
+ local v = projection.worldToView(w, self.view)
+ local centre = Vector2:new(
+ love.graphics.getWidth()/2,
+ love.graphics.getHeight()/2
+ )
+ self.view.position=self.view.position+centre-v
+end
+
+function Map:lookAt2(d, level)
+ self:lookAt({x=d.x,y=level or 0, z=d.y})
+end
+
+function Map:lookAt3(x, y, level)
+ self:lookAt({x=x, y=level or 0, z=y})
end
-function Map:addCharacter(character)
- self.character = character
+function Map:lookingAt(level)
+ local centre = Vector2:new(
+ love.graphics.getWidth()/2,
+ love.graphics.getHeight()/2
+ )
+ return projection.viewToWorld(centre,self.view,level)
end
function Map:update (dt)
@@ -71,11 +100,12 @@ function Map:update (dt)
if self.canDrag and self.mdp then
local mx, my = love.mouse.getPosition()
local mp = Vector2:new(mx, my)
- self.view.position = self.view.position - ((self.mdp - mp) / self.view.scale)
- self.mdp = mp
+ self.view.position = self.view.position + mp - self.mdp
+ self.mdp = mp
end
-
- if not self.velocity:isZero() then
+
+-- currently broken (map moving code)
+--[[ if not self.velocity:isZero() then
-- Get the rate of movement
local speed = Map.WALK_SPEED
if love.keyboard.isDown("lctrl") then
@@ -86,7 +116,7 @@ function Map:update (dt)
self.velocity = self.velocity * speed
self.view.position = self.view.position + self.velocity
self.velocity:zero()
- end
+ end]]
if not self.editorEnabled then
self.character:update(dt)
end
@@ -187,7 +217,7 @@ function Map:isSelectedTile (x, y, checkEditorEnabled)
end
function Map:tileToCoords (tx, ty)
- local temp = self.view.position + projection.vx*(tx-1) + projection.vz*(ty-1)
+ local temp = projection.worldToView3(tx-1,ty-1,self.view)/self.view.scale
return math.floor(temp.x), math.floor(temp.y+projection.vx.y)
end
@@ -247,6 +277,8 @@ function Map:mousereleased (x, y, button)
end
end
+local lastView = nil
+
function Map:keypressed (key, unicode)
if key == "h" then
self.displayControls = not self.displayControls
@@ -254,32 +286,18 @@ function Map:keypressed (key, unicode)
self.editorEnabled = not self.editorEnabled
elseif key == "=" then
if self.view.scale <= (Map.MAX_SCALE - 0.09) then
+ local temp = self:lookingAt()
self.view.scale = self.view.scale + 0.1
+ self:lookAt(temp)
end
elseif key == "-" then
if self.view.scale >= (Map.MIN_SCALE + 0.09) then
+ local temp = self:lookingAt()
self.view.scale = self.view.scale - 0.1
+ self:lookAt(temp)
end
elseif key == " " then
self.canDrag = true
- elseif self.selectedTile and Map.TILES then
- local s = self.selectedTile
- if key == "`" or key == "delete" then
- love.event.push("kp", "backspace")
- elseif key == "backspace" then
- if Map.TILES[s.x] then
- Map.TILES[s.x][s.y] = nil
- end
- else
- local byte = string.byte(key)
- if byte >= 48 and byte <= 57 then
- local tile = byte - 48 -- to get numbers 0-9
- if Map.IMAGES.tiles[tile] and Map.TILES then
- if not Map.TILES[s.x] then Map.TILES[s.x] = {} end
- Map.TILES[s.x][s.y] = tile
- end
- end
- end
end
if self.editorEnabled then
@@ -288,25 +306,43 @@ function Map:keypressed (key, unicode)
if key == "up" then
if t.y-1 >= 1 then
self.selectedTile.y = t.y - 1
- self.view.position = self.view.position + projection.vz
+ self.view.position = self.view.position + projection.vz
end
end
if key == "down" then
if t.y+1 <= self.size.length then
self.selectedTile.y = t.y + 1
- self.view.position = self.view.position - projection.vz
+ self.view.position = self.view.position - projection.vz
end
end
if key == "left" then
if t.x-1 >= 1 then
self.selectedTile.x = t.x - 1
- self.view.position = self.view.position + projection.vx
+ self.view.position = self.view.position + projection.vx
end
end
if key == "right" then
if t.x+1 <= self.size.width then
self.selectedTile.x = t.x + 1
- self.view.position = self.view.position - projection.vx
+ self.view.position = self.view.position - projection.vx
+ end
+ end
+ if t and Map.TILES then
+ if key == "`" or key == "delete" then
+ love.event.push("kp", "backspace")
+ elseif key == "backspace" then
+ if Map.TILES[t.x] then
+ Map.TILES[t.x][t.y] = nil
+ end
+ else
+ local byte = string.byte(key)
+ if byte >= 48 and byte <= 57 then
+ local tile = byte - 48 -- to get numbers 0-9
+ if Map.IMAGES.tiles[tile] and Map.TILES then
+ if not Map.TILES[t.x] then Map.TILES[t.x] = {} end
+ Map.TILES[t.x][t.y] = tile
+ end
+ end
end
end
end

No commit comments for this range

Something went wrong with that request. Please try again.