This repository has been archived by the owner on Nov 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 46
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #146 from Ceasiumz/new
src revise
- Loading branch information
Showing
20 changed files
with
491 additions
and
0 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
pub fn animeBlock(self : Game) -> Unit { | ||
if game.counter > 10 && game.counter < 29 && game.counter % 6 == 0 { | ||
for i in [0,1,2]{ | ||
self.block[i].changeColor_random() | ||
} | ||
} | ||
if game.counter > 28 && game.counter < 41 && game.counter % 4 == 0 { | ||
for i in [0,1,2]{ | ||
self.block[i].changeColor_random() | ||
} | ||
} | ||
if game.counter > 41 && game.counter < 51 && game.counter % 2 == 0 { | ||
for i in [0,1,2]{ | ||
self.block[i].changeColor_random() | ||
} | ||
} | ||
} | ||
pub fn animeBall(self : Game) -> Unit { | ||
if game.counter > 50 && game.counter < 66 { | ||
self.ball.x += 7 | ||
} | ||
} | ||
|
||
pub fn animeProgressBar(self : Game) -> Unit { | ||
if self.pbar.width < 120 && self.coin > 0 { | ||
if self.time % 5 == 0 { | ||
self.pbar.width += 2 | ||
} | ||
} else { | ||
self.pbar.width = 0 | ||
} | ||
} | ||
|
||
pub fn animeSprite(self : Game) -> Unit { | ||
@wasm4.trace("anicounter\{self.counter} \{self.block[1].sprite_block.x}") | ||
if self.counter >= 0 { | ||
if true { | ||
self.block[0].sprite_block.x = 20 | ||
self.block[0].sprite_block.y = 30 | ||
self.block[1].sprite_block.x = 20 | ||
self.block[1].sprite_block.y = 30 | ||
self.block[2].sprite_block.x = 20 | ||
self.block[2].sprite_block.y = 30 | ||
} | ||
} else { | ||
self.block[0].sprite_block.x = self.block[0].x | ||
self.block[0].sprite_block.y = self.block[0].y | ||
self.block[1].sprite_block.x = self.block[1].x | ||
self.block[1].sprite_block.y = self.block[1].y | ||
self.block[2].sprite_block.x = self.block[2].x | ||
self.block[2].sprite_block.y = self.block[2].y | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,136 @@ | ||
struct Color { | ||
mut palette : UInt | ||
} | ||
|
||
pub fn Color::new() -> Color { | ||
{ palette: 2 } | ||
} | ||
|
||
let randomer : @random.Rand = @random.Rand::new() | ||
|
||
fn draw(self : Game) -> Unit { | ||
//drawBkg(self) | ||
drawBlock(self) | ||
drawBall(self) | ||
drawCoin(self) | ||
drawUI() | ||
drawProgressBar(self) | ||
} | ||
|
||
//fn drawBkg(self : Game) -> Unit { | ||
// @wasm4.set_draw_colors(index=1, 2) | ||
// @wasm4.set_draw_colors(index=2, 1) | ||
// @wasm4.set_draw_colors(index=3, 4) | ||
// @wasm4.set_draw_colors(index=4, 3) | ||
// @wasm4.blit( | ||
// hex, | ||
// 0, | ||
// 0, | ||
// 160, | ||
// 160, | ||
// { one_bit_per_pixel: true, flip_x: false, flip_y: false, rotate: false }, | ||
// ) | ||
//} | ||
|
||
fn drawBlock(self : Game) -> Unit { | ||
for i in [0, 1, 2] { | ||
self.block[i].x = 20 + 45 * i | ||
} | ||
for i in [0, 1, 2] { | ||
@wasm4.set_draw_colors(self.block[i].color.palette) | ||
@wasm4.rect( | ||
self.block[i].x, | ||
self.block[i].y, | ||
self.block[i].width, | ||
self.block[i].height, | ||
) | ||
if game.counterFlag == false { | ||
drawSprite(self, i) | ||
} | ||
} | ||
} | ||
|
||
fn drawSprite(self : Game, blockindex : Int) -> Unit { | ||
@wasm4.set_draw_colors(1) | ||
match self.block[blockindex].event_block { | ||
"None" => return | ||
"Sun" => { | ||
self.block[blockindex].sprite_block = { | ||
x: self.block[blockindex].x + 3, | ||
y: 43, | ||
sprite: sun_sprite, | ||
} | ||
@wasm4.blit( | ||
self.block[blockindex].sprite_block.sprite, | ||
self.block[blockindex].sprite_block.x, | ||
self.block[blockindex].sprite_block.y, | ||
SunWidth, | ||
SunHeight, | ||
{ one_bit_per_pixel: true, flip_x: false, flip_y: false, rotate: false }, | ||
) | ||
} | ||
"Moon" => { | ||
self.block[blockindex].sprite_block = { | ||
x: self.block[blockindex].x + 3, | ||
y: 43, | ||
sprite: moon_sprite, | ||
} | ||
@wasm4.blit( | ||
self.block[blockindex].sprite_block.sprite, | ||
self.block[blockindex].sprite_block.x, | ||
self.block[blockindex].sprite_block.y, | ||
MoonWidth, | ||
MoonHeight, | ||
{ one_bit_per_pixel: true, flip_x: false, flip_y: false, rotate: false }, | ||
) | ||
} | ||
_ => return | ||
} | ||
} | ||
|
||
fn drawBall(self : Game) -> Unit { | ||
if game.gameOverFlag == false { | ||
@wasm4.set_draw_colors(3) | ||
@wasm4.rect(31, 108, 100, 5) | ||
@wasm4.set_draw_colors(2) | ||
@wasm4.oval(self.ball.x, self.ball.y, self.ball.width, self.ball.height) | ||
} | ||
} | ||
|
||
fn drawProgressBar(self : Game) -> Unit { | ||
@wasm4.set_draw_colors(2) | ||
@wasm4.rect(self.pbar.x, self.pbar.y, self.pbar.width, self.pbar.height) | ||
} | ||
|
||
fn drawCoin(self : Game) -> Unit { | ||
@wasm4.set_draw_colors(2) | ||
@wasm4.text(":\{self.coin}", 74, 150) | ||
coin_sprite.blit( | ||
64, | ||
150, | ||
8, | ||
8, | ||
{ one_bit_per_pixel: false, flip_x: false, flip_y: false, rotate: false }, | ||
) | ||
} | ||
|
||
fn drawUI() -> Unit { | ||
@wasm4.text("G a c h a", 44, 6) | ||
@wasm4.text( | ||
"Generator:\{(event.sunAmount-event.moonAmount).reinterpret_as_int()}", | ||
32, | ||
127, | ||
) | ||
} | ||
|
||
pub fn changeColor(self : Block) -> Unit { | ||
if self.color.palette < 4 { | ||
self.color.palette += 1 | ||
} else { | ||
self.color.palette = 1 | ||
} | ||
} | ||
|
||
pub fn changeColor_random(self : Block) -> Unit { | ||
self.color.palette = randomer.uint(limit=3) + 2 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
let commonEventChance : UInt = 30 | ||
|
||
let rareEventChance : UInt = 10 | ||
|
||
let superRareEventChance : UInt = 1 | ||
|
||
pub let commonEvent = ["Sun", "Moon"] | ||
|
||
pub let rareEvent = ["Hurricane"] | ||
|
||
pub let superRareEvent = ["Win"] | ||
|
||
let commonEventAmount : UInt = commonEvent.length().reinterpret_as_uint() | ||
|
||
let rareEventAmount : UInt = rareEvent.length().reinterpret_as_uint() | ||
|
||
let superRareEventAmount : UInt = superRareEvent.length().reinterpret_as_uint() | ||
|
||
pub struct Event { | ||
mut sunAmount : UInt | ||
mut moonAmount : UInt | ||
} | ||
|
||
let event : Event = { sunAmount: 0, moonAmount: 0 } | ||
|
||
pub fn runEvents() -> Unit { | ||
|
||
if game.time % 300 == 0 { | ||
game.coin += event.sunAmount.reinterpret_as_int() | ||
game.coin -= event.moonAmount.reinterpret_as_int() | ||
} | ||
} | ||
fn getEvent() -> String { | ||
let rand = (game.time + randomer.uint()) % 100 | ||
if rand < commonEventChance { | ||
getCommonEvent() | ||
} else if rand < commonEventChance + rareEventChance { | ||
getRareEvent() | ||
} else if rand < commonEventChance + rareEventChance + superRareEventChance { | ||
getSuperRareEvent() | ||
} else { | ||
"None" | ||
} | ||
} | ||
fn getCommonEvent() -> String { | ||
let rand = ((game.time + randomer.uint()) % commonEventAmount).reinterpret_as_int() | ||
commonEvent[rand] | ||
} | ||
|
||
fn getRareEvent() -> String { | ||
let rand = ((game.time + randomer.uint()) % rareEventAmount).reinterpret_as_int() | ||
rareEvent[rand] | ||
} | ||
|
||
fn getSuperRareEvent() -> String { | ||
let rand = ((game.time + randomer.uint()) % superRareEventAmount).reinterpret_as_int() | ||
superRareEvent[rand] | ||
} | ||
|
||
pub fn identifyEvent(eventName : String) -> String { | ||
match eventName { | ||
"None" => @wasm4.trace("None") | ||
"Sun" => runSunEvent() | ||
"Moon" => runMoonEvent() | ||
_ => @wasm4.trace("Unknown event") | ||
} | ||
eventName | ||
} | ||
|
||
|
||
fn runSunEvent() -> Unit { | ||
event.sunAmount += 1 | ||
@wasm4.trace("Sun") | ||
} | ||
|
||
fn runMoonEvent() -> Unit { | ||
event.moonAmount += 1 | ||
@wasm4.trace("Moon") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
pub struct Block { | ||
mut width : Int | ||
mut height : Int | ||
mut x : Int | ||
mut y : Int | ||
mut color : Color | ||
mut event_block : String | ||
mut sprite_block : MoveSprite | ||
} | ||
|
||
pub fn Block::new() -> Block { | ||
{ width: 30, | ||
height: 70, | ||
x: 0, | ||
y: 20, | ||
color: Color::new(), | ||
event_block : "None", | ||
sprite_block : MoveSprite::new() | ||
} | ||
} | ||
|
||
pub struct Ball { | ||
mut width : Int | ||
mut height : Int | ||
mut x : Int | ||
mut y : Int | ||
mut color : Color | ||
} | ||
|
||
pub fn Ball::new() -> Ball { | ||
{ width: 25, height: 25, x: 19, y: 98, color: Color::new() } | ||
} | ||
|
||
pub struct Game { | ||
mut block : Array[Block] | ||
mut ball : Ball | ||
mut frame_count : Int | ||
mut prev_gamepad : @wasm4.GamePad | ||
mut coin : Int | ||
mut time : UInt | ||
mut delay : UInt | ||
mut counter : UInt | ||
mut counterFlag : Bool | ||
mut pbar :Block | ||
mut gameOverFlag:Bool | ||
} | ||
|
||
pub fn Game::new() -> Game { | ||
{ | ||
block: [Block::new(), Block::new(), Block::new()], | ||
ball: Ball::new(), | ||
frame_count: 0, | ||
prev_gamepad: @wasm4.GamePad::default(), | ||
coin: 0, | ||
time: 0, | ||
delay: 0, | ||
counter: 65, | ||
counterFlag: false, | ||
pbar: Block::{width: 0, height: 10, x: 20, y: 138, color: Color::new(), event_block : "None", sprite_block : MoveSprite::new()} , | ||
gameOverFlag: false | ||
} | ||
} | ||
|
||
pub fn input(self : Game) -> Unit { | ||
let gamepad = @wasm4.get_gamepad() | ||
if game.counterFlag { | ||
game.counter -= 1 | ||
animeBlock(self) | ||
animeBall(self) | ||
animeSprite(self) | ||
} | ||
if game.counter == 0 { | ||
for i in [0, 1, 2] { | ||
self.block[i].changeColor_random() | ||
self.block[i].event_block = identifyEvent(getEvent()) | ||
|
||
@wasm4.trace("\{self.time}") | ||
|
||
} | ||
|
||
game.counter = 65 | ||
game.counterFlag = false | ||
game.ball.x = 19 | ||
if game.block[0].color.palette == game.block[1].color.palette { | ||
if game.block[1].color.palette == game.block[2].color.palette { | ||
music() | ||
} | ||
} else { | ||
nothing() | ||
prize() | ||
} | ||
} | ||
if gamepad != self.prev_gamepad { | ||
if gamepad.button_1 && game.coin > 0 && game.counterFlag == false { | ||
game.coin -= 1 | ||
game.counterFlag = true | ||
} | ||
} | ||
self.prev_gamepad = gamepad | ||
} | ||
|
||
fn gameOver() -> Unit { | ||
@wasm4.text("GAME OVER", 44, 105) | ||
@wasm4.text("press R to restart", 8, 115) | ||
game.time += 1 | ||
game.coin = 0 | ||
game.gameOverFlag = true | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
pub fn hello() -> String { | ||
"Hello, world!" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
test "hello" { | ||
if @lib.hello() != "Hello, world!" { | ||
fail!("@lib.hello() != \"Hello, world!\"") | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{} |
Oops, something went wrong.