Differnet palette test, added mouse pressed and mouse held

This commit is contained in:
Bobby Lucero 2024-04-27 18:17:04 -04:00
parent df9e305828
commit d6c8ad3641
5 changed files with 119 additions and 18 deletions

View File

@ -1,7 +1,21 @@
from scene import Scene
fireGradient = [9, 9, 18, 18, 17, 16, 15, 14, 15, 14, 16, 14, 14,14,16, 2, 1]
waterGradient = [9, 9, 43, 43, 42, 41, 40, 39, 40, 39, 41, 39, 39,39,41, 2, 1]
white = 63
fire1 = 6
fire2 = 5
fire3 = 4
fire4 = 3
fire5 = 2
fire6 = 56
water1 = 31
water2 = 30
water3 = 29
water4 = 28
fireGradient = [white, white, fire1, fire1, fire2, fire3, fire4, fire3, fire4, fire5, fire6, fire6, fire6]
waterGradient = [white, white, water1, water2, water3, water4, water4]
class Particle:
def __init__(self, x, y, velX, velY):
@ -26,7 +40,7 @@ class Palette(Scene):
for i in range(8):
for j in range(8):
rectangle(10 + (i * 20), 10 + (j * 20), 18, 18, (j * 8 + i))
text(str(j * 8 + i), 10 + (i * 20), 10 + (j * 20), 9)
text(str(j * 8 + i), 11 + (i * 20), 10 + (j * 20), 63)
class Main(Scene):
@ -71,7 +85,7 @@ class Main(Scene):
p.velX += rnd(-0.3,0.3)
p.velY += rnd(-0.3,0.3)
idx = int(p.size / 5.0 * len(fireGradient) - 1)
idx = int(p.size / 5.0 * len(waterGradient) - 1)
p.c = waterGradient[(len(waterGradient) - 1) - idx]
@ -82,18 +96,21 @@ class Main(Scene):
if(p.size < 0):
self.waterParts.remove(p)
if(key(67)):
x1 = mouseX + (sin(self.counter * 0.1) * 60)
y1 = mouseY + (cos(self.counter * 0.1) * 60)
x2 = mouseX + (sin(self.counter * 0.1 + (3.141592653)) * 60)
y2 = mouseY + (cos(self.counter * 0.1 + (3.141592653)) * 60)
for i in range(2):
if(mouse(0)):
rad = sin(self.counter * 0.01) * 50
x1 = mouseX + (sin(self.counter * 0.1) * rad)
y1 = mouseY + (cos(self.counter * 0.1) * rad)
x2 = mouseX + (sin(self.counter * 0.1 + (3.141592653)) * rad)
y2 = mouseY + (cos(self.counter * 0.1 + (3.141592653)) * rad)
for i in range(10):
self.fireParts.append(Particle(x1, y1, rnd(-1,1) + mouseVelX * 0.25, rnd(-1,1) + mouseVelY * 0.25))
self.waterParts.append(Particle(x2, y2, rnd(-1,1) + mouseVelX * 0.25, rnd(-1,1) + mouseVelY * 0.25))
def draw(self):
clear(44)
clear(0)
for p in self.fireParts:
if(p.size <= 1):
pixel(p.x, p.y, p.c)
@ -105,10 +122,12 @@ class Main(Scene):
pixel(p.x, p.y, p.c)
else:
circle(p.x, p.y, int(p.size), p.c)
text("C to add particles, T to toggle palette", 3, 3, 0)
text("C to add particles, T to toggle palette", 2, 2, 30)
text("Num Particles: " + str(len(self.fireParts) + len(self.waterParts)), 3, 16, 0)
text("Num Particles: " + str(len(self.fireParts) + len(self.waterParts)), 2, 15, 9)
text("C to add particles, T to toggle palette", 3, 3, 59)
text("C to add particles, T to toggle palette", 2, 2, 31)
text("Num Particles: " + str(len(self.fireParts) + len(self.waterParts)), 3, 16, 59)
text("Num Particles: " + str(len(self.fireParts) + len(self.waterParts)), 2, 15, 30)
text("FPS: " + str(fps()), 3, 29, 59)
text("FPS: " + str(fps()), 2, 28, 29)
paletteScene = Palette()
@ -147,6 +166,10 @@ def update():
else:
current_scene = mainScene
if(mousep(1)):
current_scene.paused = not current_scene.paused
if(not current_scene.paused):
current_scene.update()
current_scene.draw()

View File

@ -1,7 +1,7 @@
class Scene:
def __init__(self):
pass
self.paused = False
def update(self):
pass

64
resources/thecosmos.hex Normal file
View File

@ -0,0 +1,64 @@
161928
271b3b
5e1d5d
9c144d
ce2029
f06c1a
ffd95a
f3ad20
e97c07
c94814
9c3824
591d35
1d3926
456130
568c20
a4bf20
c5e848
5dae27
288a3f
005a41
003441
1c2945
e9dc4e
a2e66f
5acc9a
3c9aab
245473
183454
132233
384e80
287cb8
2fbfcd
db5ebe
a346bd
7a38c9
5037ab
272a6e
222347
3f2966
7f3896
ab3293
cf4c98
e77988
fdd5b1
fdaf88
f27f72
ba4a54
543545
3d2839
913f39
c75a4a
ed9353
f7bf6f
c4ccc7
8394a6
5c627d
374252
282e2f
1d2029
2b3147
5d7585
9cbab0
d7eac1
ffffe0

View File

@ -29,7 +29,7 @@ Pycron::Pycron() {
bindMethods();
m_graphics = new Graphics{virtualScreenWidth, virtualScreenHeight, initialScale};
m_graphics->loadPalette("../resources/palette2.hex");
m_graphics->loadPalette("resources/thecosmos.hex");
m_graphics->bindMethods(m_vm);
m_graphics->updateVMVars(m_vm);
m_stateManager = new StateManager(this);
@ -66,6 +66,8 @@ void Pycron::bindMethods() {
m_vm->bind(m_vm->builtins, "fps() -> int", getFPS);
m_vm->bind(m_vm->builtins, "keyp(keycode: int) -> bool", getKeyPressed);
m_vm->bind(m_vm->builtins, "key(keycode: int) -> bool", getKeyDown);
m_vm->bind(m_vm->builtins, "mousep(button: int) -> bool", getMousePressed);
m_vm->bind(m_vm->builtins, "mouse(button: int) -> bool", getMouseDown);
}
@ -107,3 +109,13 @@ pkpy::PyObject *Pycron::getKeyDown(pkpy::VM *vm, pkpy::ArgsView args) {
return pkpy::py_var(vm, held);
}
pkpy::PyObject *Pycron::getMousePressed(pkpy::VM *vm, pkpy::ArgsView args) {
bool held = IsMouseButtonPressed(pkpy::py_cast<int>(vm, args[0]));
return pkpy::py_var(vm, held);
}
pkpy::PyObject *Pycron::getMouseDown(pkpy::VM *vm, pkpy::ArgsView args) {
bool held = IsMouseButtonDown(pkpy::py_cast<int>(vm, args[0]));
return pkpy::py_var(vm, held);
}

View File

@ -35,5 +35,7 @@ public:
static pkpy::PyObject* getFPS(pkpy::VM* vm, pkpy::ArgsView args);
static pkpy::PyObject* getKeyPressed(pkpy::VM* vm, pkpy::ArgsView args);
static pkpy::PyObject* getKeyDown(pkpy::VM* vm, pkpy::ArgsView args);
static pkpy::PyObject* getMousePressed(pkpy::VM* vm, pkpy::ArgsView args);
static pkpy::PyObject* getMouseDown(pkpy::VM* vm, pkpy::ArgsView args);
};