Code Monkey home page Code Monkey logo

fp1's Introduction

My Library: 2hdtp/universe and 2hdtp/image (universe relies on image)

My name: Rob Russell

I created a basic framework for a game and experimented with changing game states and creating classes with closures to instantiate game objects that will be updated and their positions used to re-render the scene.

I got some help from the examples and documentation on the universe library.

I basically started with this example from the documentation above:

(define (create-UFO-scene height)
  (underlay/xy (rectangle 100 100 "solid" "white") 50 height UFO))
 
(define UFO
  (underlay/align "center"
                  "center"
                  (circle 10 "solid" "green")
                  (rectangle 40 4 "solid" "green")))
 
(animate create-UFO-scene)

And then re-wrote and extended it once I read through the docs a little more and understood what was going on.

####My basic player class:

;;player class
(define (player x y speed health)
  (define (dispatch id)
    (cond
      [(equal? id 'x) x]
      [(equal? id 'y) y]
      [(equal? id 'speed) speed]
      [(equal? id 'health) health]
      [(equal? id 'move-left) (set! x (- x 2))]
      [(equal? id 'move-right) (set! x (+ x 2))]
      [(equal? id 'move-down) (set! y (+ y speed))]
      [else (error "PLAYER -- no match for: " id)]))
  dispatch)

####I also imported an image to use for the player:

(define bob-sprite (rotate 180 (bitmap "Plane.png")))

####And added some input handling:

;;handle input
(define (handle-key-down world key)
  (cond
    [(key=? key "left") (bob 'move-left)]
    [(key=? key "right") (bob 'move-right)]
    [else world]
    )
)

(define (handle-key-up world key)
  (cond
    [(key=? key "left") bob]
    [(key=? key "right") bob]
    [else world]
    ))

This library makes input handling super easy, and now that I understand the game cycle, I can quickly add a lot more functionality to this. Currently the ship just goes from the top to the bottom of the screen, and you can press the arrow keys to make it go a little left or a little right as it travels down. Definitely gonna mess with this some more over the break, finally having fun in Racket!

Image of my game

fp1's People

Contributors

marksherman avatar robdoesweb avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.