From c9b60c569f2ad015f043667c44ff9f43d50ec2e5 Mon Sep 17 00:00:00 2001 From: equa Date: Tue, 20 Apr 2021 18:20:05 -0500 Subject: death screen --- font/Montserrat-Bold.ttf | Bin 0 -> 244468 bytes font/Montserrat-Regular.ttf | Bin 0 -> 245708 bytes font/Montserrat-SemiBold.ttf | Bin 0 -> 243816 bytes font/OFL.txt | 93 +++++++++++++++++++++++++++++++++++++++++++ lib/death.fnl | 35 ++++++++++++++++ lib/font.fnl | 2 + lib/game.fnl | 60 ++++++++++++++++------------ lib/main.fnl | 10 +++-- lib/player.fnl | 6 +-- 9 files changed, 175 insertions(+), 31 deletions(-) create mode 100644 font/Montserrat-Bold.ttf create mode 100644 font/Montserrat-Regular.ttf create mode 100644 font/Montserrat-SemiBold.ttf create mode 100644 font/OFL.txt create mode 100644 lib/death.fnl create mode 100644 lib/font.fnl diff --git a/font/Montserrat-Bold.ttf b/font/Montserrat-Bold.ttf new file mode 100644 index 0000000..221819b Binary files /dev/null and b/font/Montserrat-Bold.ttf differ diff --git a/font/Montserrat-Regular.ttf b/font/Montserrat-Regular.ttf new file mode 100644 index 0000000..8d443d5 Binary files /dev/null and b/font/Montserrat-Regular.ttf differ diff --git a/font/Montserrat-SemiBold.ttf b/font/Montserrat-SemiBold.ttf new file mode 100644 index 0000000..f8a43f2 Binary files /dev/null and b/font/Montserrat-SemiBold.ttf differ diff --git a/font/OFL.txt b/font/OFL.txt new file mode 100644 index 0000000..7881887 --- /dev/null +++ b/font/OFL.txt @@ -0,0 +1,93 @@ +Copyright 2011 The Montserrat Project Authors (https://github.com/JulietaUla/Montserrat) + +This Font Software is licensed under the SIL Open Font License, Version 1.1. +This license is copied below, and is also available with a FAQ at: +http://scripts.sil.org/OFL + + +----------------------------------------------------------- +SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007 +----------------------------------------------------------- + +PREAMBLE +The goals of the Open Font License (OFL) are to stimulate worldwide +development of collaborative font projects, to support the font creation +efforts of academic and linguistic communities, and to provide a free and +open framework in which fonts may be shared and improved in partnership +with others. + +The OFL allows the licensed fonts to be used, studied, modified and +redistributed freely as long as they are not sold by themselves. The +fonts, including any derivative works, can be bundled, embedded, +redistributed and/or sold with any software provided that any reserved +names are not used by derivative works. The fonts and derivatives, +however, cannot be released under any other type of license. The +requirement for fonts to remain under this license does not apply +to any document created using the fonts or their derivatives. + +DEFINITIONS +"Font Software" refers to the set of files released by the Copyright +Holder(s) under this license and clearly marked as such. This may +include source files, build scripts and documentation. + +"Reserved Font Name" refers to any names specified as such after the +copyright statement(s). + +"Original Version" refers to the collection of Font Software components as +distributed by the Copyright Holder(s). + +"Modified Version" refers to any derivative made by adding to, deleting, +or substituting -- in part or in whole -- any of the components of the +Original Version, by changing formats or by porting the Font Software to a +new environment. + +"Author" refers to any designer, engineer, programmer, technical +writer or other person who contributed to the Font Software. + +PERMISSION & CONDITIONS +Permission is hereby granted, free of charge, to any person obtaining +a copy of the Font Software, to use, study, copy, merge, embed, modify, +redistribute, and sell modified and unmodified copies of the Font +Software, subject to the following conditions: + +1) Neither the Font Software nor any of its individual components, +in Original or Modified Versions, may be sold by itself. + +2) Original or Modified Versions of the Font Software may be bundled, +redistributed and/or sold with any software, provided that each copy +contains the above copyright notice and this license. These can be +included either as stand-alone text files, human-readable headers or +in the appropriate machine-readable metadata fields within text or +binary files as long as those fields can be easily viewed by the user. + +3) No Modified Version of the Font Software may use the Reserved Font +Name(s) unless explicit written permission is granted by the corresponding +Copyright Holder. This restriction only applies to the primary font name as +presented to the users. + +4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font +Software shall not be used to promote, endorse or advertise any +Modified Version, except to acknowledge the contribution(s) of the +Copyright Holder(s) and the Author(s) or with their explicit written +permission. + +5) The Font Software, modified or unmodified, in part or in whole, +must be distributed entirely under this license, and must not be +distributed under any other license. The requirement for fonts to +remain under this license does not apply to any document created +using the Font Software. + +TERMINATION +This license becomes null and void if any of the above conditions are +not met. + +DISCLAIMER +THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT +OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER RIGHT. IN NO EVENT SHALL THE +COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, +INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL +DAMAGES, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING +FROM, OUT OF THE USE OR INABILITY TO USE THE FONT SOFTWARE OR FROM +OTHER DEALINGS IN THE FONT SOFTWARE. diff --git a/lib/death.fnl b/lib/death.fnl new file mode 100644 index 0000000..8456827 --- /dev/null +++ b/lib/death.fnl @@ -0,0 +1,35 @@ +(local state (require :lib.state)) +(local font (require :lib.font)) + +(fn draw [self] + (local (width height) (love.graphics.getDimensions)) + (state.draw self.present-state) + ;; TODO: translation + (love.graphics.reset) + (love.graphics.setColor 0.8 0.8 0.8 (/ (math.max 0 (- self.age 30)) 10)) + (love.graphics.setFont font.big) + (love.graphics.printf "moli a" (- (/ width 2) 500) (- (/ height 2) 64) 1000 :center) + (love.graphics.setFont font.small) + (love.graphics.printf "nena Z li open e musi sin" (- (/ width 2) 500) (+ (/ height 2)) 1000 :center)) + +(fn update [self] + ;; TODO: actually update in case it returns something else + (state.update self.present-state) + (set self.age (math.min 40 (+ self.age 1))) + (if self.transition + self.future-state + nil)) + +(fn keypressed [self key scancode repeat] + (when (and (not repeat) (= key :z)) + (set self.transition true)) + ) + +(fn init [self present-state future-state] + (setmetatable + {: present-state + : future-state + :age 0} + self)) + +{state.draw draw state.init init state.update update state.keypressed keypressed} diff --git a/lib/font.fnl b/lib/font.fnl new file mode 100644 index 0000000..73a18b8 --- /dev/null +++ b/lib/font.fnl @@ -0,0 +1,2 @@ +{:small (love.graphics.newFont "font/Montserrat-SemiBold.ttf" 12) + :big (love.graphics.newFont "font/Montserrat-SemiBold.ttf" 48)} diff --git a/lib/game.fnl b/lib/game.fnl index 3f99550..229f433 100644 --- a/lib/game.fnl +++ b/lib/game.fnl @@ -4,6 +4,7 @@ (local vec (require :lib.vec)) (local entity (require :lib.entity)) (local player (require :lib.player)) +(local death (require :lib.death)) (local fv (require :fennel.view)) (fn lerp* [a b c d x] @@ -68,7 +69,12 @@ (tset e entity.duration (- (entity.duration e) 1)) (if (= (entity.duration e) 0) (tset self.entities id nil)))) - ) + ;; TODO: we should do this for only the first death frame + (if (not self.entities.player) + ;; TODO: new game + (state.init death self ((. (getmetatable self) :inner-init) + (getmetatable self) 1 self)) + nil)) (fn id [x] x) @@ -165,29 +171,33 @@ self.max-radius (+ self.target-radius 4)))))) +(fn inner-init [self level past] + (let [past (or past {}) + width 64 + height 64] + (setmetatable + {:width width + :height height + :radius (or past.radius 32) + :target-radius (or past.radius 32) + :max-radius (/ (math.min height width) 2) + :min-radius 16 + :level level + :tick 0 + :rate 6 + :entities {:player (entity.init player {:x 31.5 :y 31.5})} + :grid (new-grid width height #(if (= (math.random 6) 1) + (if (> $1 44) + (cell.init cells.life) + (< $1 10) + (cell.init cells.brain) + nil) + nil)) + :grid-alt (new-grid width height #nil) + } + self))) + (fn init [self] - (local width 64) - (local height 64) - (setmetatable - {:width width - :height height - :ship {:x 31 :y 31} - :radius 32 - :target-radius 32 - :max-radius (/ (math.min height width) 2) - :min-radius 16 - :tick 0 - :rate 6 - :entities {:player (entity.init player {:x 32 :y 32})} - :grid (new-grid width height #(if (= (math.random 6) 1) - (if (> $1 44) - (cell.init cells.life) - (< $1 10) - (cell.init cells.brain) - nil) - nil)) - :grid-alt (new-grid width height #nil) - } - self)) + (self.inner-init self 1)) -{state.draw draw state.init init state.update update state.keypressed keypressed} +{: inner-init state.draw draw state.init init state.update update state.keypressed keypressed} diff --git a/lib/main.fnl b/lib/main.fnl index 71319b8..9af1bb8 100644 --- a/lib/main.fnl +++ b/lib/main.fnl @@ -2,6 +2,7 @@ (local proto (require :lib.proto)) (local state (require :lib.state)) (local game (require :lib.game)) +(local font (require :lib.font)) (local profi (require :vendor.ProFi)) (local profi? false) @@ -14,6 +15,7 @@ :lib.bullet :lib.cells :lib.game + :lib.death :lib.main]) ;; the @@ -25,8 +27,7 @@ (set love.frame 0)) (love.keyboard.setKeyRepeat true) (global the-state (state.init game)) - (global messages (or messages {})) - (print "a")) + (global messages (or messages {}))) (fn love.draw [] (match (pcall #(state.draw the-state)) @@ -36,7 +37,9 @@ (print (.. "draw \n" x)) (love.graphics.print (.. "draw: \n" x)))) (love.graphics.reset) + ;; (love.graphics.setFont font.small) (love.graphics.print (love.timer.getFPS)) + ;; (love.graphics.print :soko font.big 100 100) (when true ;; debug stuff (love.graphics.print (table.concat (lume.map messages #$.msg) @@ -58,7 +61,8 @@ (os.exit))) ;; TODO: make state changes actually possible (match (pcall #(state.update the-state)) - (true x) nil + (true next) (global the-state next) + (true nil) nil (false x) (do (print (.. "update: \n" x)) (table.insert messages diff --git a/lib/player.fnl b/lib/player.fnl index 8e31a18..5fca05a 100644 --- a/lib/player.fnl +++ b/lib/player.fnl @@ -8,7 +8,7 @@ (setmetatable {entity.position pos entity.velocity {:x 0 :y 0} :target-spin 0 - :shot-age 0 + :shot-age 20 :direction 0} self)) @@ -37,8 +37,8 @@ (entity.init bullet (vec.clone (entity.position self)) - {:x (+ (* (math.cos self.direction) 0.6)) - :y (+ (* (math.sin self.direction) 0.6))})))) + {:x (+ v.x (* (math.cos self.direction) 0.6)) + :y (+ v.y (* (math.sin self.direction) 0.6))})))) (fn draw [self game id] (love.graphics.setColor 1 1 1) -- cgit 1.3.0-6-gf8a5