aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIndrajith K L2021-08-02 13:48:25 +0530
committerIndrajith K L2021-08-02 13:48:25 +0530
commit7d988900e2f73992fea504419d61d4cdf759fedf (patch)
treea722fc38bcd7d9b4155c54b32acf9a5dc44cfdd9
parent2ff207a1d30830aeca2ea9e5d085a55ee3448ab0 (diff)
downloadrebirth-wren-7d988900e2f73992fea504419d61d4cdf759fedf.tar.gz
rebirth-wren-7d988900e2f73992fea504419d61d4cdf759fedf.tar.bz2
rebirth-wren-7d988900e2f73992fea504419d61d4cdf759fedf.zip
* Basic Game State Implementation
* Code Refactoring
-rw-r--r--game_state.wren17
-rw-r--r--level_map.wren (renamed from level.wren)22
-rw-r--r--levels/level1.wren14
-rw-r--r--levels/level2.wren (renamed from map.wren)2
-rw-r--r--main.wren11
5 files changed, 48 insertions, 18 deletions
diff --git a/game_state.wren b/game_state.wren
new file mode 100644
index 0000000..94e8a99
--- /dev/null
+++ b/game_state.wren
@@ -0,0 +1,17 @@
+class GameState {
+ construct new() {
+
+ }
+
+ switch(level) {
+ _currentLevel = level.new()
+ }
+
+ update() {
+ _currentLevel.update()
+ }
+
+ draw(dt) {
+ _currentLevel.draw(dt)
+ }
+} \ No newline at end of file
diff --git a/level.wren b/level_map.wren
index 4aaacea..2bfb941 100644
--- a/level.wren
+++ b/level_map.wren
@@ -3,33 +3,29 @@ import "graphics" for ImageData
import "math" for Math
import "./layer_type" for LayerType
-class Level {
- construct new(levelName) {
- _levelData = Json.load("assets/%(levelName).json")
- var tileSheetData = _levelData["tilesets"][0] // Assuming I only use single tilesheet
+class LevelMap {
+ construct new(mapName) {
+ _mapData = Json.load("assets/%(mapName).json")
+ var tileSheetData = _mapData["tilesets"][0] // Assuming there is only a single tilesheet/level
_tileSheet = ImageData.loadFromFile("assets/%(tileSheetData["image"])")
_tileSheetH = tileSheetData["imageheight"]
_tileSheetW = tileSheetData["imagewidth"]
_tileH = tileSheetData["tileheight"]
_tileW = tileSheetData["tilewidth"]
- _levelHeight = _levelData["height"]
- _levelWidth = _levelData["width"]
- _layers = _levelData["layers"]
+ _mapHeight = _mapData["height"]
+ _mapWidth = _mapData["width"]
+ _layers = _mapData["layers"]
_rows = Math.floor(_tileSheetW/_tileW)
_cols = Math.floor(_tileSheetH/_tileH)
}
- load(levelName) {
-
- }
-
draw(x, y) {
var startX = x
var startY = y
for(layer in _layers) {
var index = 0
- for(levelY in 0...(_levelHeight)) {
- for(levelX in 0...(_levelWidth)) {
+ for(mapYV in 0...(_mapHeight)) {
+ for(mapXV in 0...(_mapWidth)) {
if((layer["type"] == LayerType.Tile) && (layer["visible"] == true)) {
var tileIndex = layer["data"][index]
if (tileIndex > 0) {
diff --git a/levels/level1.wren b/levels/level1.wren
new file mode 100644
index 0000000..c485924
--- /dev/null
+++ b/levels/level1.wren
@@ -0,0 +1,14 @@
+import "./level_map" for LevelMap
+class Level1 {
+ construct new() {
+ _level1 = LevelMap.new("level1")
+ }
+
+ update() {
+
+ }
+
+ draw(dt) {
+ _level1.draw(0,0)
+ }
+} \ No newline at end of file
diff --git a/map.wren b/levels/level2.wren
index e9a37ee..6323ad5 100644
--- a/map.wren
+++ b/levels/level2.wren
@@ -1,4 +1,4 @@
-class Map {
+class Level2 {
construct new() {
}
diff --git a/main.wren b/main.wren
index 7e39844..370860e 100644
--- a/main.wren
+++ b/main.wren
@@ -6,12 +6,14 @@ import "math" for Math
import "config" for Config
import "input" for Keyboard
import "./controls" for Controls
-import "./level" for Level
+import "./game_state" for GameState
+import "./levels/level1" for Level1
class Main {
construct new() {
Config.setup()
- __level = Level.new("level1")
+ __gameState = GameState.new()
+ __gameState.switch(Level1)
}
init() {
@@ -22,11 +24,12 @@ class Main {
if(Controls.detect(Config.KeyboardConstants["QUIT"])) {
Process.exit(0)
}
+ __gameState.update()
}
- draw(alpha) {
+ draw(dt) {
Canvas.cls(Color.pink)
- __level.draw(0,0)
+ __gameState.draw(dt)
}
}