From 5bd12d5a658c1cd710bc950be971ebe3993ed11d Mon Sep 17 00:00:00 2001 From: Indrajith K L Date: Tue, 3 Aug 2021 02:22:07 +0530 Subject: * Menu Screen * SFX * Player Sprites --- screens/credit_screen.wren | 13 ++++++ screens/menu_screen.wren | 105 +++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 118 insertions(+) create mode 100644 screens/credit_screen.wren create mode 100644 screens/menu_screen.wren (limited to 'screens') diff --git a/screens/credit_screen.wren b/screens/credit_screen.wren new file mode 100644 index 0000000..3b54d2b --- /dev/null +++ b/screens/credit_screen.wren @@ -0,0 +1,13 @@ +class CreditScreen { + construct new() { + + } + + update() { + + } + + draw(dt) { + + } +} \ No newline at end of file diff --git a/screens/menu_screen.wren b/screens/menu_screen.wren new file mode 100644 index 0000000..e065765 --- /dev/null +++ b/screens/menu_screen.wren @@ -0,0 +1,105 @@ +import "graphics" for Canvas, Color +import "./controls" for Controls +import "config" for Config +import "levels/level1" for Level1 +import "screens/credit_screen" for CreditScreen +import "audio" for AudioEngine +import "font" for Font +import "math" for Math + +class MenuScreen { + construct new(gameState) { + __gameState = gameState + // var channel = AudioEngine.play("menu_music") + // channel.volume = 0.5 + _selectedMenuIdx = 0 + _prevMenuIdx = 0 + _fadeFrame = 255 + _menuItems = [ + { + "name": "Start", + "selected": true, + "class": Level1, + "font": Font.default, + "padding": 20 + }, + { + "name": "Credits", + "selected": false, + "class": CreditScreen, + "font": Font.default, + "padding": 40 + } + ] + + } + + update() { + if(Controls.isKeyDown(Config.KeyboardConstants["SELECT"])) { + __gameState.switch(Level1) + } + + if(Controls.justPressed(Config.KeyboardConstants["UP"])) { + _prevMenuIdx = _selectedMenuIdx + if((_selectedMenuIdx-1) < 0) { + _selectedMenuIdx = (_menuItems.count - 1) + } else { + _selectedMenuIdx = _selectedMenuIdx - 1 + } + AudioEngine.play("select") + } + + if(Controls.justPressed(Config.KeyboardConstants["DOWN"])) { + _prevMenuIdx = _selectedMenuIdx + if((_selectedMenuIdx+1) > (_menuItems.count - 1)) { + _selectedMenuIdx = 0 + } else { + _selectedMenuIdx = _selectedMenuIdx + 1 + } + AudioEngine.play("select") + } + + if(_prevMenuIdx!=_selectedMenuIdx) { + _menuItems[_prevMenuIdx]["selected"] = false + _menuItems[_selectedMenuIdx]["selected"] = true + } + + // _fadeFrame = (_fadeFrame+3) > 255 ? 0 : _fadeFrame + 3 + + _fadeFrame = Math.floor(127 + (127 * Math.cos(System.clock))) + System.print(_fadeFrame) + } + + draw(dt) { + + drawTitle() + + for(menuItem in _menuItems) { + drawMenu(menuItem) + } + + drawBlinker() + } + + drawTitle() { + Canvas.print("REBIRTH",Config.W/2 - 40,Config.H/2 - 20, Color.white, "font_title") + } + + drawMenu(menuItem) { + var x = Config.W/2 - ((menuItem["name"].count * 8)/2) + var y = Config.H/2 + menuItem["padding"] + Canvas.print(menuItem["name"],x ,y , menuItem["selected"] ? Color.red : Color.white, menuItem["font"]) + if(menuItem["selected"]) { + Canvas.print(">",x - 10 ,y , Color.red, menuItem["font"]) + } + // Canvas.print("Credits", Config.W/2 - 28, Config.H/2 + 40, Color.white, Font.default) + } + + drawBlinker() { + Canvas.print("Press X to start",Config.W/2 - 64,Config.H/2 + 100, Color.new(255, 255, 255, _fadeFrame), Font.default) + } +} + +/* +(Character length * 8 ) / 2 +*/ \ No newline at end of file -- cgit v1.2.3