2021-08-09 11:28:04 +02:00
|
|
|
// title: game title
|
|
|
|
// author: Fabien Freling
|
2021-08-09 18:14:19 +02:00
|
|
|
// desc: (Major Jam 8)
|
2021-08-09 11:28:04 +02:00
|
|
|
// script: wren
|
|
|
|
|
2021-08-09 18:14:19 +02:00
|
|
|
import "random" for Random
|
|
|
|
|
|
|
|
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)
|
|
|
|
}
|
2021-08-10 14:49:13 +02:00
|
|
|
|
|
|
|
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))
|
|
|
|
}
|
2021-08-09 18:14:19 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
class World {
|
|
|
|
construct new() {
|
|
|
|
_t = 0
|
|
|
|
_stars = []
|
2021-08-10 14:49:13 +02:00
|
|
|
_player = Ship.new(W / 2, H / 2)
|
|
|
|
|
|
|
|
// init background
|
2021-08-09 18:14:19 +02:00
|
|
|
for (i in 0..W) {
|
|
|
|
update()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
2021-08-10 14:49:13 +02:00
|
|
|
_player.update()
|
|
|
|
|
2021-08-09 18:14:19 +02:00
|
|
|
for (s in _stars) {
|
|
|
|
s.update()
|
|
|
|
}
|
2021-08-10 14:49:13 +02:00
|
|
|
// collect passed stars
|
|
|
|
while (_stars.count > 0 && _stars[0].isPassed) {
|
|
|
|
_stars.removeAt(0)
|
|
|
|
}
|
2021-08-09 18:14:19 +02:00
|
|
|
// small stars
|
|
|
|
if (_t % 30 == 0) {
|
|
|
|
_stars.add(Star.new(W, R.int(0,H), 1, 1, 12))
|
|
|
|
}
|
|
|
|
// medium stars
|
|
|
|
var width = 10
|
2021-08-10 14:49:13 +02:00
|
|
|
var spaceBetween = width * 10
|
2021-08-09 18:14:19 +02:00
|
|
|
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()
|
|
|
|
}
|
2021-08-10 14:49:13 +02:00
|
|
|
_player.draw()
|
2021-08-09 18:14:19 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-09 11:28:04 +02:00
|
|
|
class Game is TIC{
|
2021-08-09 18:14:19 +02:00
|
|
|
state { _state }
|
|
|
|
static start { "start" }
|
|
|
|
static game { "game" }
|
2021-08-09 11:28:04 +02:00
|
|
|
|
2021-08-09 18:14:19 +02:00
|
|
|
construct new() {
|
2021-08-09 11:28:04 +02:00
|
|
|
_t=0
|
|
|
|
_x=96
|
|
|
|
_y=24
|
2021-08-09 18:14:19 +02:00
|
|
|
_state = Game.start
|
|
|
|
_world = World.new()
|
2021-08-09 11:28:04 +02:00
|
|
|
}
|
|
|
|
|
2021-08-09 18:14:19 +02:00
|
|
|
TIC() {
|
|
|
|
update()
|
|
|
|
draw()
|
|
|
|
_t=_t+1
|
|
|
|
}
|
|
|
|
|
|
|
|
update() {
|
|
|
|
_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)
|
2021-08-09 11:28:04 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// <TILES>
|
|
|
|
// 001:eccccccccc888888caaaaaaaca888888cacccccccacc0ccccacc0ccccacc0ccc
|
|
|
|
// 002:ccccceee8888cceeaaaa0cee888a0ceeccca0ccc0cca0c0c0cca0c0c0cca0c0c
|
|
|
|
// 003:eccccccccc888888caaaaaaaca888888cacccccccacccccccacc0ccccacc0ccc
|
|
|
|
// 004:ccccceee8888cceeaaaa0cee888a0ceeccca0cccccca0c0c0cca0c0c0cca0c0c
|
|
|
|
// 017:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
|
|
|
|
// 018:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
|
|
|
|
// 019:cacccccccaaaaaaacaaacaaacaaaaccccaaaaaaac8888888cc000cccecccccec
|
|
|
|
// 020:ccca00ccaaaa0ccecaaa0ceeaaaa0ceeaaaa0cee8888ccee000cceeecccceeee
|
|
|
|
// </TILES>
|
|
|
|
|
2021-08-10 14:49:13 +02:00
|
|
|
// <SPRITES>
|
|
|
|
// 000:00000000000000000ccc000000eccccc00eeeeee4ddddddd4cccccdd43ddddcc
|
|
|
|
// 001:00000000000000000000000000000000ee990000ddaa9900ddaaaa90ccaaaaa9
|
|
|
|
// 016:43dddddd4ddddddd4eeeeeee0ccccccc00000000000000000000000000000000
|
|
|
|
// 017:ddccccccddddddd0eeeeee000000000000000000000000000000000000000000
|
|
|
|
// </SPRITES>
|
|
|
|
|
2021-08-09 11:28:04 +02:00
|
|
|
// <WAVES>
|
|
|
|
// 000:00000000ffffffff00000000ffffffff
|
|
|
|
// 001:0123456789abcdeffedcba9876543210
|
|
|
|
// 002:0123456789abcdef0123456789abcdef
|
|
|
|
// </WAVES>
|
|
|
|
|
|
|
|
// <SFX>
|
|
|
|
// 000:000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000304000000000
|
|
|
|
// </SFX>
|
|
|
|
|
|
|
|
// <PALETTE>
|
|
|
|
// 000:1a1c2c5d275db13e53ef7d57ffcd75a7f07038b76425717929366f3b5dc941a6f673eff7f4f4f494b0c2566c86333c57
|
|
|
|
// </PALETTE>
|
|
|
|
|