Skip to content

Commit

Permalink
Sprites
Browse files Browse the repository at this point in the history
  • Loading branch information
Amos Wenger committed Apr 21, 2012
1 parent 87ee5d9 commit f8352db
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 3 deletions.
1 change: 0 additions & 1 deletion source/ldkit/Display.ooc
Expand Up @@ -38,7 +38,6 @@ Display: class {
sdlSurface@ w, sdlSurface@ h, sdlSurface@ pitch)

cairoContext = Context new(cairoSurface)

}

}
2 changes: 2 additions & 0 deletions source/ldkit/Loader.ooc
Expand Up @@ -4,6 +4,8 @@ import text/json, text/json/Parser // yup, we have a pure ooc reader!
import structs/[ArrayList, HashBag, Bag]
import io/FileReader

import Math

/**
* Helpers to load stuff from JSON
*/
Expand Down
63 changes: 63 additions & 0 deletions source/ldkit/Sprites.ooc
@@ -0,0 +1,63 @@

/*
* A sprite is, in the large sense, anything that can be drawn onto a display.
*/

use cairo
import cairo/Cairo

import Math, Display

Sprite: class {

pos := vec2(0.0, 0.0)
offset := vec2(0.0, 0.0)
scale := vec2(1.0, 1.0)
color := vec3(1.0, 0.0, 0.0)

alpha := 1.0
visible := true

init: func (pos: Vec2) {
this pos set!(pos)
}

draw: func (display: Display) {
if (!visible) return

cr := display cairoContext

cr save()
cr translate(pos x + offset x, pos y + offset y)
cr scale(scale x, scale y)
cr setSourceRGBA(color x, color y, color z, alpha)

paint(cr)
cr restore()
}

/*
* This is the function you want to overload
* when you have custom sprites
*/
paint: func (cr: Context) {
cr setLineWidth(3)

cr moveTo(0, 0)
cr lineTo(0, 50)
cr relLineTo(50, 0)
cr closePath()
cr stroke()
}

/*
* Free resources
*/
free: func {
// nothing to do here, but for text sprites etc., might be useful
}

}



4 changes: 2 additions & 2 deletions source/ldkit/Timing.ooc
Expand Up @@ -7,12 +7,12 @@ LTime: class {

// the number of 'ticks' since the application start-up
getTicks: static func -> Int {
Sdl getTicks()
SDL getTicks()
}

// sleep for 'delta' ticks
delay: static func (delta: UInt32) {
Sdl delay(delta)
SDL delay(delta)
}

}

0 comments on commit f8352db

Please sign in to comment.