switch richlib to use raylib.static rather than dynamic, and fix colors to always be lists of 4
This commit is contained in:
parent
de89790bff
commit
aa5c396ade
2 changed files with 59 additions and 21 deletions
|
@ -2,7 +2,8 @@
|
||||||
"""
|
"""
|
||||||
__version__ = '0.1'
|
__version__ = '0.1'
|
||||||
|
|
||||||
from ..dynamic import ffi, raylib as rl
|
from ..static import ffi, rl
|
||||||
|
#from ..dynamic import ffi, raylib as rl
|
||||||
from ..colors import *
|
from ..colors import *
|
||||||
|
|
||||||
import sys
|
import sys
|
||||||
|
@ -44,16 +45,58 @@ class Vector(list):
|
||||||
def z(self, value):
|
def z(self, value):
|
||||||
self[2] = value
|
self[2] = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def w(self):
|
||||||
|
return self[3]
|
||||||
|
|
||||||
def make_color(c):
|
@w.setter
|
||||||
if isinstance(c, str):
|
def w(self, value):
|
||||||
return globals()[c.upper()]
|
self[3] = value
|
||||||
else:
|
|
||||||
return c
|
class Color(list):
|
||||||
|
def __init__(self, s):
|
||||||
|
if isinstance(s, str):
|
||||||
|
super().__init__(globals()[s.upper()])
|
||||||
|
else:
|
||||||
|
super().__init__(s)
|
||||||
|
if len(self) == 3:
|
||||||
|
self.append(255)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def r(self):
|
||||||
|
return self[0]
|
||||||
|
|
||||||
|
@r.setter
|
||||||
|
def r(self, value):
|
||||||
|
self[0] = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def g(self):
|
||||||
|
return self[1]
|
||||||
|
|
||||||
|
@g.setter
|
||||||
|
def g(self, value):
|
||||||
|
self[1] = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def b(self):
|
||||||
|
return self[2]
|
||||||
|
|
||||||
|
@b.setter
|
||||||
|
def b(self, value):
|
||||||
|
self[2] = value
|
||||||
|
|
||||||
|
@property
|
||||||
|
def a(self):
|
||||||
|
return self[3]
|
||||||
|
|
||||||
|
@a.setter
|
||||||
|
def a(self, value):
|
||||||
|
self[3] = value
|
||||||
|
|
||||||
|
|
||||||
def clear(color=BLACK):
|
def clear(color=BLACK):
|
||||||
rl.ClearBackground(color)
|
rl.ClearBackground(Color(color))
|
||||||
|
|
||||||
|
|
||||||
class Shape:
|
class Shape:
|
||||||
|
@ -63,10 +106,7 @@ class Shape:
|
||||||
|
|
||||||
@color.setter
|
@color.setter
|
||||||
def color(self, value):
|
def color(self, value):
|
||||||
if isinstance(value, str):
|
self._color = Color(value)
|
||||||
self._color = globals()[value.upper()]
|
|
||||||
else:
|
|
||||||
self._color = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def pos(self):
|
def pos(self):
|
||||||
|
@ -82,10 +122,7 @@ class Shape:
|
||||||
|
|
||||||
@wire_color.setter
|
@wire_color.setter
|
||||||
def wire_color(self, value):
|
def wire_color(self, value):
|
||||||
if isinstance(value, str):
|
self._wire_color = Color(value)
|
||||||
self._wire_color = globals()[value.upper()]
|
|
||||||
else:
|
|
||||||
self._wire_color = value
|
|
||||||
|
|
||||||
@property
|
@property
|
||||||
def x(self):
|
def x(self):
|
||||||
|
@ -117,7 +154,7 @@ class Box(Shape):
|
||||||
self.pos = position
|
self.pos = position
|
||||||
self.size = size
|
self.size = size
|
||||||
self.color = color
|
self.color = color
|
||||||
self.wire_color = wire_color # make_color(wire_color)
|
self.wire_color = wire_color
|
||||||
self.wires = wires
|
self.wires = wires
|
||||||
|
|
||||||
# def __getattr__(self, item):
|
# def __getattr__(self, item):
|
||||||
|
@ -150,6 +187,7 @@ class Box(Shape):
|
||||||
)
|
)
|
||||||
|
|
||||||
def draw(self):
|
def draw(self):
|
||||||
|
#print("draw color ",self.color)
|
||||||
rl.DrawCubeV(self.pos, self.size, self.color)
|
rl.DrawCubeV(self.pos, self.size, self.color)
|
||||||
if self.wires:
|
if self.wires:
|
||||||
rl.DrawCubeWiresV(
|
rl.DrawCubeWiresV(
|
||||||
|
|
|
@ -5,8 +5,8 @@ HEIGHT=640
|
||||||
#CAMERA=CAMERA_FIRST_PERSON
|
#CAMERA=CAMERA_FIRST_PERSON
|
||||||
DATA_DIR="examples/models/resources/models/"
|
DATA_DIR="examples/models/resources/models/"
|
||||||
|
|
||||||
player = Box((0, 10, 20), (10, 20, 10), GREEN)
|
player = Box((0, 10, 20), (10, 20, 10), 'green')
|
||||||
enemy_box = Box((-40, 10, 0), (20, 20, 20), (70,70,70))
|
enemy_box = Box((-40, 10, 0), (20, 20, 20), (150,0,0))
|
||||||
enemy_sphere = Sphere((40, 15, 0), 15, 'gray')
|
enemy_sphere = Sphere((40, 15, 0), 15, 'gray')
|
||||||
castle = Actor("castle", collision_radius=15)
|
castle = Actor("castle", collision_radius=15)
|
||||||
castle.z=-50
|
castle.z=-50
|
||||||
|
@ -28,13 +28,13 @@ def update():
|
||||||
player.pos.z -= 2
|
player.pos.z -= 2
|
||||||
|
|
||||||
if player.check_collision(enemy_box) or player.check_collision(enemy_sphere) or player.check_collision(castle):
|
if player.check_collision(enemy_box) or player.check_collision(enemy_sphere) or player.check_collision(castle):
|
||||||
player.color = RED
|
player.color = 'red'
|
||||||
else:
|
else:
|
||||||
player.color = GREEN
|
player.color = 'green'
|
||||||
|
|
||||||
|
|
||||||
def draw3d():
|
def draw3d():
|
||||||
rl.ClearBackground(WHITE)
|
clear('white')
|
||||||
enemy_box.draw()
|
enemy_box.draw()
|
||||||
enemy_sphere.draw()
|
enemy_sphere.draw()
|
||||||
player.draw()
|
player.draw()
|
||||||
|
|
Reference in a new issue