diff --git a/cart.wren b/cart.wren index f00ef14..762cd28 100644 --- a/cart.wren +++ b/cart.wren @@ -1,17 +1,87 @@ // title: game title // author: Fabien Freling -// desc: short description +// desc: (Major Jam 8) // script: wren -class Game is TIC{ +import "random" for Random - construct new(){ +var W = 240 +var H = 136 +var R = Random.new() + +class Star { + construct new(x, y, size, scrollSpeed, color) { + _x = x + _y = y + _size = size + _scrollSpeed = scrollSpeed + _color = color + } + + update() { + _x = _x - _scrollSpeed + } + + draw() { + TIC.circ(_x, _y, _size, _color) + } +} + +class World { + construct new() { + _t = 0 + _stars = [] + for (i in 0..W) { + update() + } + } + + update() { + for (s in _stars) { + s.update() + } + // small stars + if (_t % 30 == 0) { + _stars.add(Star.new(W, R.int(0,H), 1, 1, 12)) + } + // medium stars + var width = 10 + var spaceBetween = width * 5 + var speed = 0.1 + var mediumTick = (spaceBetween + width) / speed + if (_t % mediumTick == 0) { + _stars.add(Star.new(W, R.int(0,H), width, speed, 13)) + } + _t = _t + 1 + } + + draw() { + for (s in _stars) { + s.draw() + } + } +} + +class Game is TIC{ + state { _state } + static start { "start" } + static game { "game" } + + construct new() { _t=0 _x=96 _y=24 + _state = Game.start + _world = World.new() } - TIC(){ + TIC() { + update() + draw() + _t=_t+1 + } + + update() { if(TIC.btn(0)){ _y=_y-1 } @@ -24,12 +94,14 @@ class Game is TIC{ if(TIC.btn(3)){ _x=_x+1 } - - TIC.cls(13) - TIC.spr(1+((_t%60)/30|0)*2,_x,_y,14,3,0,0,2,2) - TIC.print("HELLO WORLD!",84,84) - - _t=_t+1 + _world.update() + } + + draw() { + TIC.cls(0) + _world.draw() + //TIC.spr(1+((_t%60)/30|0)*2,_x,_y,14,3,0,0,2,2) + //TIC.print("HELLO WORLD!",84,84) } }