Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@sinistersnare
Last active December 23, 2015 16:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sinistersnare/6665526 to your computer and use it in GitHub Desktop.
Save sinistersnare/6665526 to your computer and use it in GitHub Desktop.
drop.clj
(ns cljdx.core
(:require [cljdx.drop :as drop])
(:import (com.badlogic.gdx.backends.lwjgl LwjglApplication)))
(defn -main
"I don't do a whole lot."
[& args]
(LwjglApplication.
(cljdx.drop.) "Hello, Clojure!" 800 480 true))
(ns cljdx.drop
(:import (com.badlogic.gdx Game Screen Gdx))
(:require [cljdx.gamescreen :as gamescreen])
(:gen-class
:name cljdx.drop
:extends com.badlogic.gdx.Game))
(defn -create [^Game this]
(.setScreen this (gamescreen/screen)))
(ns cljdx.gamescreen
(:import (java.util Iterator)
(com.badlogic.gdx Gdx Screen )
(com.badlogic.gdx Input$Keys)
(com.badlogic.gdx.audio Sound Music)
(com.badlogic.gdx.graphics.g2d BitmapFont SpriteBatch)
(com.badlogic.gdx.graphics GL10 OrthographicCamera Texture)
(com.badlogic.gdx.math MathUtils Rectangle Vector3)
(com.badlogic.gdx.utils Array TimeUtils)))
(defn screen []
(println "GRAPHICS" (.glGetString Gdx/gl (GL10/GL_RENDERER)))
(println "VERSION" (.glGetString Gdx/gl (GL10/GL_VERSION)))
(let [batch (SpriteBatch.) font (BitmapFont.)
drop-image (Texture. (.internal Gdx/files "assets/droplet.png"))
bucket-image (Texture. (.internal Gdx/files "assets/bucket.png"))
drop-sound (.newSound Gdx/audio (.internal Gdx/files "assets/drop.wav"))
rain-music (.newMusic Gdx/audio (.internal Gdx/files "assets/rain.mp3"))
camera (OrthographicCamera.) bucket (Rectangle.)
raindrops (Array.) last-drop-time (atom nil)]
(defn spawn-raindrop []
(let [raindrop (Rectangle.)]
(set! (.x raindrop) (MathUtils/random 0 (- 800 64)))
(set! (.y raindrop) 480)
(set! (.width raindrop) 64)
(set! (.height raindrop) 64)
(.add raindrops raindrop)
(reset! last-drop-time (TimeUtils/nanoTime)) ;possible fuckup
(println @last-drop-time)))
(proxy [Screen] []
(show []
(doto rain-music
(.setLooping true)
(.play))
(do
( .setToOrtho camera false 800 480))
;use a map for this, rinstead of ugly objects
(set! (.x bucket) (- (/ 800 2) (/ 64 2))) ;center bucket
(set! (.y bucket) 20)
(set! (.width bucket) 64)
(set! (.height bucket) 64)
;(do spawn-raindrop) ;doesnt work...
)
(render [delta]
(.begin batch)
(.draw font batch "Hello, Clojure" 150 150)
(.end batch))
(dispose []
(do
(.dispose font)
(.dispose batch)
(.dispose drop-image)
(.dispose bucket-image)
(.dispose drop-sound)
(.dispose rain-music)))
(hide [])
(pause [])
(resize [w h])
(resume []))))
(defproject cljdx "0.1.0-SNAPSHOT"
:description "FIXME: write description"
;:plugins [[s3-wagon-private "1.1.1"]] ;delthis
:dependencies [[org.clojure/clojure "1.5.1"]
[com.badlogicgames.gdx/gdx "0.9.9-SNAPSHOT"]
[com.badlogicgames.gdx/gdx-backend-lwjgl "0.9.9-SNAPSHOT"]
[lwjgl-natives.com.badlogicgames.gdx/lwjgl-natives "0.9.9-SNAPSHOT"] ;using local
[natives.com.badlogicgames.gdx/natives "0.9.9-SNAPSHOT"]] ; using local
:repositories [["sonatype" {:url "https://oss.sonatype.org/content/repositories/snapshots/"
;; If a repository contains releases only setting
;; :snapshots to false will speed up dependencies.
:snapshots true
;; Disable signing releases for this repo.
;; (Not recommended.)
:sign-releases false
;; You can also set the policies for how to handle
;; :checksum failures to :fail, :warn, or :ignore.
:checksum :warn
;; How often should this repository be checked
;; for updates? (:daily, :always, or :never)
:update :daily
;; You can also apply them to releases only:
:releases {:checksum :fail :update :daily}}]
["local" ~(str (.toURI (java.io.File. "repo")))]]
:resource-paths ["res"]
:main cljdx.core
:aot [cljdx.drop])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment