diff --git a/cart.wren b/cart.wren
index 762cd28..0b69007 100644
--- a/cart.wren
+++ b/cart.wren
@@ -25,28 +25,100 @@ class Star {
draw() {
TIC.circ(_x, _y, _size, _color)
}
+
+ isPassed {
+ _x + _size < 0
+ }
+}
+
+class Bullet {
+ construct new(x, y) {
+ _x = x
+ _y = y
+ _speed = 5
+ }
+
+ update() {
+ _x = _x + _speed
+ }
+
+ draw() {
+ TIC.rect(_x, _y, 3, 1, 4)
+ }
+}
+
+class Ship {
+ construct new(x, y) {
+ _x = x
+ _y = y
+ _speed = 1
+ _bullets = []
+ }
+
+ update() {
+ if (TIC.btn(0)) {
+ _y = _y - _speed
+ }
+ if (TIC.btn(1)) {
+ _y = _y + _speed
+ }
+ if (TIC.btn(2)) {
+ _x = _x - _speed
+ }
+ if (TIC.btn(3)) {
+ _x = _x + _speed
+ }
+
+ if (TIC.btnp(4, 5, 10)) {
+ shoot()
+ }
+
+ for (b in _bullets) {
+ b.update()
+ }
+ }
+
+ draw() {
+ TIC.spr(256, _x, _y, 0, 1, 0, 0, 2, 2)
+ for (b in _bullets) {
+ b.draw()
+ }
+ }
+
+ shoot() {
+ _bullets.add(Bullet.new(_x + 8, _y + 8))
+ }
}
class World {
construct new() {
_t = 0
_stars = []
+ _player = Ship.new(W / 2, H / 2)
+
+ // init background
for (i in 0..W) {
update()
}
}
update() {
+ _player.update()
+
for (s in _stars) {
s.update()
}
+ // collect passed stars
+ while (_stars.count > 0 && _stars[0].isPassed) {
+ _stars.removeAt(0)
+ }
// 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 spaceBetween = width * 10
var speed = 0.1
var mediumTick = (spaceBetween + width) / speed
if (_t % mediumTick == 0) {
@@ -59,6 +131,7 @@ class World {
for (s in _stars) {
s.draw()
}
+ _player.draw()
}
}
@@ -82,18 +155,6 @@ class Game is TIC{
}
update() {
- if(TIC.btn(0)){
- _y=_y-1
- }
- if(TIC.btn(1)){
- _y=_y+1
- }
- if(TIC.btn(2)){
- _x=_x-1
- }
- if(TIC.btn(3)){
- _x=_x+1
- }
_world.update()
}
@@ -116,6 +177,13 @@ class Game is TIC{
// 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
//
+//
+// 000:00000000000000000ccc000000eccccc00eeeeee4ddddddd4cccccdd43ddddcc
+// 001:00000000000000000000000000000000ee990000ddaa9900ddaaaa90ccaaaaa9
+// 016:43dddddd4ddddddd4eeeeeee0ccccccc00000000000000000000000000000000
+// 017:ddccccccddddddd0eeeeee000000000000000000000000000000000000000000
+//
+
//
// 000:00000000ffffffff00000000ffffffff
// 001:0123456789abcdeffedcba9876543210