Starting work on a skill tree node graph both in raylib and emacs
This commit is contained in:
parent
d1a24b08a1
commit
db3f5d9407
27
Diagrams.org
Normal file
27
Diagrams.org
Normal file
@ -0,0 +1,27 @@
|
||||
* The topics
|
||||
#+begin_src syntree
|
||||
("Game Programming Fundamentals"
|
||||
("Math" "_:Data Structures" "_:Algorithms" "_:Linear Algebra")
|
||||
("Engineering"
|
||||
("Machine Architecture" "_:CPU Design" "_:Memory Hierarchy" "_:Processes" "_:Concurrency")
|
||||
"_:Networking"
|
||||
"_:Compilers"
|
||||
("Operating Systems" "_:Scheduling" "_:File Systems" "_:Virtual Memory")))
|
||||
#+end_src
|
||||
|
||||
#+RESULTS:
|
||||
#+begin_example
|
||||
Game Programming Fundamentals
|
||||
._________________________________________|_________________________________________.
|
||||
| |
|
||||
Math Engineering
|
||||
.______________|_____________. .________________________________._|________._________________________.
|
||||
| | | | | | |
|
||||
.______|______. .____|___. .______|_____. Machine Architecture .____|___. .___|___. Operating Systems
|
||||
|_____________| |________| |____________| .______________._____|_______.___________. |________| |_______| .____________.|_____________.
|
||||
Data Structures Algorithms Linear Algebra | | | | Networking Compilers | | |
|
||||
.____|___. ._______|______. .___|___. .____|____. .____|___. ._____|____. .______|_____.
|
||||
|________| |______________| |_______| |_________| |________| |__________| |____________|
|
||||
CPU Design Memory Hierarchy Processes Concurrency Scheduling File Systems Virtual Memory
|
||||
|
||||
#+end_example
|
96
skilltree.py
Normal file
96
skilltree.py
Normal file
@ -0,0 +1,96 @@
|
||||
import pyray as RL
|
||||
from pyray import (Rectangle as Rect, Vector2 as Vec2)
|
||||
import math
|
||||
import pdb
|
||||
import random
|
||||
from typing import Optional, Tuple, List
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
screen_width = 1280
|
||||
screen_height = 1024
|
||||
|
||||
node_width = 200
|
||||
node_height = 60
|
||||
node_font_height = 24
|
||||
|
||||
default_font = RL.get_font_default()
|
||||
|
||||
@dataclass
|
||||
class Node:
|
||||
text: str
|
||||
rect: Rect
|
||||
|
||||
@dataclass
|
||||
class World:
|
||||
nodes: List[Node]
|
||||
dragging_node: Optional[Tuple[Node, Tuple[float, float]]] = None
|
||||
|
||||
global w
|
||||
def init():
|
||||
global w
|
||||
nodes = [Node("Node1",Rect(50,50,node_width,node_height)),Node("Node2",Rect(150,150,node_width,node_height))]
|
||||
w = World(nodes)
|
||||
|
||||
|
||||
def player_input():
|
||||
if RL.is_mouse_button_pressed(0):
|
||||
w.dragging_node = None
|
||||
for node in w.nodes:
|
||||
mouse_pos = RL.get_mouse_position()
|
||||
if RL.check_collision_point_rec(mouse_pos, node.rect):
|
||||
w.dragging_node = node, (node.rect.x - mouse_pos.x, node.rect.y - mouse_pos.y)
|
||||
break
|
||||
if RL.is_mouse_button_released(0):
|
||||
w.dragging_node = None
|
||||
|
||||
if w.dragging_node:
|
||||
node, offset_x, offset_y = w.dragging_node[0], *w.dragging_node[1]
|
||||
mouse_pos = RL.get_mouse_position()
|
||||
node.rect.x, node.rect.y = mouse_pos.x + offset_x, mouse_pos.y + offset_y
|
||||
|
||||
|
||||
def update():
|
||||
pass
|
||||
|
||||
def draw():
|
||||
RL.begin_drawing()
|
||||
RL.clear_background(RL.RAYWHITE)
|
||||
|
||||
for node in w.nodes:
|
||||
rect_offset = Rect(node.rect.x + 2, node.rect.y + 2, node.rect.width, node.rect.height)
|
||||
RL.draw_rectangle_lines_ex(rect_offset, 2, RL.BLACK)
|
||||
RL.draw_rectangle_rec(node.rect, RL.WHITE)
|
||||
RL.draw_rectangle_lines_ex(node.rect, 1, RL.BLACK)
|
||||
text_width = RL.measure_text(node.text, node_font_height)
|
||||
pos = Vec2(
|
||||
node.rect.x + node.rect.width / 2 - text_width / 2,
|
||||
node.rect.y + node.rect.height / 2 - node_font_height / 2,
|
||||
)
|
||||
RL.draw_text_ex(default_font, node.text, pos, node_font_height, 1, RL.BLACK)
|
||||
|
||||
node1 = w.nodes[0]
|
||||
node2 = w.nodes[1]
|
||||
start_pos = Vec2(node1.rect.x + node1.rect.width // 2, node1.rect.y + node1.rect.height)
|
||||
end_pos = Vec2(node2.rect.x + node2.rect.width // 2, node2.rect.y)
|
||||
# RL.draw_line_bezier(start_pos, end_pos, 3, RL.BLUE)
|
||||
# c1 = start_pos
|
||||
# c1.x += 50
|
||||
# c1.y += 50
|
||||
# c2 = end_pos
|
||||
# c2.y -= 50
|
||||
mid_point = RL.vector2_subtract(end_pos, start_pos)
|
||||
mid_control = RL.vector2_add(mid_point, Vec2(50,50))
|
||||
points = [start_pos, start_pos, mid_point, mid_control, end_pos, end_pos]
|
||||
# points = [start_pos, c1, c2, mid_point, end_pos]
|
||||
RL.draw_spline_bezier_cubic(points, 6, 3, RL.BLUE)
|
||||
|
||||
RL.end_drawing()
|
||||
|
||||
RL.init_window(screen_width, screen_height, "Skilltree");
|
||||
RL.set_target_fps(60)
|
||||
|
||||
init()
|
||||
while not RL.window_should_close():
|
||||
player_input()
|
||||
update()
|
||||
draw()
|
39
starter.py
Normal file
39
starter.py
Normal file
@ -0,0 +1,39 @@
|
||||
import pyray as RL
|
||||
from pyray import (Rectangle as Rect)
|
||||
import math
|
||||
import pdb
|
||||
import random
|
||||
from typing import Optional, Tuple, List
|
||||
from dataclasses import dataclass, field
|
||||
|
||||
screen_width = 1280
|
||||
screen_height = 1024
|
||||
|
||||
@dataclass
|
||||
class World:
|
||||
pass
|
||||
|
||||
def init():
|
||||
pass
|
||||
|
||||
def player_input():
|
||||
pass
|
||||
|
||||
def update():
|
||||
pass
|
||||
|
||||
def draw():
|
||||
RL.begin_drawing()
|
||||
RL.clear_background(RL.WHITE)
|
||||
|
||||
RL.end_drawing()
|
||||
|
||||
RL.init_window(screen_width, screen_height, "Starter");
|
||||
RL.set_target_fps(60)
|
||||
|
||||
init()
|
||||
while not RL.window_should_close():
|
||||
player_input()
|
||||
update()
|
||||
draw()
|
||||
|
Loading…
x
Reference in New Issue
Block a user