mirror of https://github.com/profan/ld-39-jam.git
horrible staggering through rendertargets later, minimap!
This commit is contained in:
parent
569fef0adc
commit
9fe981b3a6
16
Asteroid.gd
16
Asteroid.gd
|
@ -9,10 +9,12 @@ var max_rot_vel = 2.5 # degrees per second
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
randomize()
|
randomize()
|
||||||
velocity.x = floor(rand_range(-max_vel, max_vel))
|
# velocity.x = floor(rand_range(-max_vel, max_vel))
|
||||||
velocity.y = floor(rand_range(-max_vel, max_vel))
|
# velocity.y = floor(rand_range(-max_vel, max_vel))
|
||||||
rect.size.x = floor(rand_range(32, 64))
|
rect.size.x = floor(rand_range(32, 64))
|
||||||
rect.size.y = floor(rand_range(32, 64))
|
rect.size.y = floor(rand_range(32, 64))
|
||||||
|
rect.pos.x = -rect.size.x / 2
|
||||||
|
rect.pos.y = -rect.size.y / 2
|
||||||
rot_vel = deg2rad(floor(rand_range(1, max_rot_vel)))
|
rot_vel = deg2rad(floor(rand_range(1, max_rot_vel)))
|
||||||
set_fixed_process(true)
|
set_fixed_process(true)
|
||||||
|
|
||||||
|
@ -26,13 +28,13 @@ func wrap(v, v_min, v_max):
|
||||||
|
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
|
|
||||||
var cur_pos = get_pos()
|
# var cur_pos = get_pos()
|
||||||
cur_pos.x = wrap(cur_pos.x, 1, get_viewport().get_rect().size.x)
|
# cur_pos.x = wrap(cur_pos.x, 1, get_viewport().get_rect().size.x)
|
||||||
cur_pos.y = wrap(cur_pos.y, 1, get_viewport().get_rect().size.y)
|
# cur_pos.y = wrap(cur_pos.y, 1, get_viewport().get_rect().size.y)
|
||||||
set_pos(cur_pos)
|
# set_pos(cur_pos)
|
||||||
|
|
||||||
self.move(velocity)
|
self.move(velocity)
|
||||||
self.rotate(rot_vel)
|
self.rotate(rot_vel)
|
||||||
|
|
||||||
func _draw():
|
func _draw():
|
||||||
draw_rect(rect, Color(0x42, 0x8b, 0xca))
|
draw_rect(rect, Color(1, 1, 1))
|
|
@ -9,6 +9,9 @@ var current_threshold = 5
|
||||||
# delay between each spawn of asteroid
|
# delay between each spawn of asteroid
|
||||||
var spawn_delay = 1 # seconds
|
var spawn_delay = 1 # seconds
|
||||||
|
|
||||||
|
# deps
|
||||||
|
onready var map = get_parent().get_node("Minimap")
|
||||||
|
|
||||||
func _ready():
|
func _ready():
|
||||||
set_fixed_process(true)
|
set_fixed_process(true)
|
||||||
|
|
||||||
|
@ -27,8 +30,8 @@ func _fixed_process(delta):
|
||||||
var y = floor(rand_range(1, get_viewport().get_rect().size.y))
|
var y = floor(rand_range(1, get_viewport().get_rect().size.y))
|
||||||
var spawn_pos = Vector2(x, y)
|
var spawn_pos = Vector2(x, y)
|
||||||
|
|
||||||
print(spawn_pos)
|
|
||||||
new_asteroid.set_pos(spawn_pos)
|
new_asteroid.set_pos(spawn_pos)
|
||||||
get_parent().add_child(new_asteroid) # add to tree
|
get_parent().add_child(new_asteroid) # add to tree
|
||||||
|
map.register_entity(new_asteroid) # register with minimap
|
||||||
|
|
||||||
total_asteroids += 1
|
total_asteroids += 1
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
extends Node2D
|
||||||
|
|
||||||
|
var entities
|
||||||
|
var cam_pos = Vector2(0, 0)
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func init(ents):
|
||||||
|
entities = ents
|
||||||
|
|
||||||
|
func it_changed(new_pos):
|
||||||
|
cam_pos = get_tree().get_root().get_node("Game/Player").get_pos()
|
||||||
|
update()
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
var vp_rect = get_viewport().get_rect()
|
||||||
|
# draw player in center
|
||||||
|
var p_mw = (vp_rect.size.x / 2) - 1
|
||||||
|
var p_mh = (vp_rect.size.y / 2) - 1
|
||||||
|
draw_rect(Rect2(p_mw, p_mh, 2, 2), Color(0, 1, 0))
|
||||||
|
for e in entities:
|
||||||
|
var ent = e.get_ref()
|
||||||
|
var ent_pos = ent.get_global_pos()
|
||||||
|
var s_mw = vp_rect.size.x / 2
|
||||||
|
var s_mh = vp_rect.size.y / 2
|
||||||
|
var s_x = s_mw + (ent_pos.x / vp_rect.size.x) - (cam_pos.x / vp_rect.size.x)
|
||||||
|
var s_y = s_mh + (ent_pos.y / vp_rect.size.y) - (cam_pos.y / vp_rect.size.y)
|
||||||
|
draw_rect(Rect2(s_x, s_y, 2, 2), Color(1, 1, 1))
|
39
Game.tscn
39
Game.tscn
|
@ -1,14 +1,43 @@
|
||||||
[gd_scene load_steps=3 format=1]
|
[gd_scene load_steps=5 format=1]
|
||||||
|
|
||||||
[ext_resource path="res://Player.tscn" type="PackedScene" id=1]
|
[ext_resource path="res://Minimap.tscn" type="PackedScene" id=1]
|
||||||
[ext_resource path="res://AsteroidSpawner.tscn" type="PackedScene" id=2]
|
[ext_resource path="res://AsteroidSpawner.tscn" type="PackedScene" id=2]
|
||||||
|
[ext_resource path="res://Player.tscn" type="PackedScene" id=3]
|
||||||
|
[ext_resource path="res://raw/space.png" type="Texture" id=4]
|
||||||
|
|
||||||
[node name="Game" type="Node"]
|
[node name="Game" type="Node"]
|
||||||
|
|
||||||
[node name="Player" parent="." instance=ExtResource( 1 )]
|
[node name="Minimap" parent="." instance=ExtResource( 1 )]
|
||||||
|
|
||||||
transform/pos = Vector2( 92.7742, 71.7896 )
|
|
||||||
|
|
||||||
[node name="AsteroidSpawner" parent="." instance=ExtResource( 2 )]
|
[node name="AsteroidSpawner" parent="." instance=ExtResource( 2 )]
|
||||||
|
|
||||||
|
[node name="Player" parent="." instance=ExtResource( 3 )]
|
||||||
|
|
||||||
|
transform/pos = Vector2( 92.7742, 71.7896 )
|
||||||
|
|
||||||
|
[node name="ParallaxBackground" type="ParallaxBackground" parent="."]
|
||||||
|
|
||||||
|
layer = -1
|
||||||
|
offset = Vector2( 0, 0 )
|
||||||
|
rotation = 0.0
|
||||||
|
scale = Vector2( 1, 1 )
|
||||||
|
scroll/offset = Vector2( 0, 0 )
|
||||||
|
scroll/base_offset = Vector2( 0, 0 )
|
||||||
|
scroll/base_scale = Vector2( 1, 1 )
|
||||||
|
scroll/limit_begin = Vector2( 0, 0 )
|
||||||
|
scroll/limit_end = Vector2( 0, 0 )
|
||||||
|
scroll/ignore_camera_zoom = true
|
||||||
|
|
||||||
|
[node name="ParallaxLayer" type="ParallaxLayer" parent="ParallaxBackground"]
|
||||||
|
|
||||||
|
motion/scale = Vector2( 0.25, 0.25 )
|
||||||
|
motion/offset = Vector2( 0, 0 )
|
||||||
|
motion/mirroring = Vector2( 0, 0 )
|
||||||
|
|
||||||
|
[node name="Sprite" type="Sprite" parent="ParallaxBackground/ParallaxLayer"]
|
||||||
|
|
||||||
|
texture = ExtResource( 4 )
|
||||||
|
region = true
|
||||||
|
region_rect = Rect2( 0, 0, 8192, 8192 )
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,42 @@
|
||||||
|
extends Control
|
||||||
|
|
||||||
|
var offset_pos = Vector2(32, 32)
|
||||||
|
|
||||||
|
onready var render_target = get_node("Viewport")
|
||||||
|
onready var tex_frame = get_node("TextureFrame")
|
||||||
|
|
||||||
|
var entities = Array()
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
set_fixed_process(true)
|
||||||
|
tex_frame.set_texture(render_target.get_render_target_texture())
|
||||||
|
render_target.init(entities)
|
||||||
|
tex_frame.set_pos(Vector2(32, 32))
|
||||||
|
|
||||||
|
func register_entity(e):
|
||||||
|
entities.append(weakref(e))
|
||||||
|
render_target.init(entities)
|
||||||
|
|
||||||
|
func collect_entities():
|
||||||
|
var to_remove
|
||||||
|
for i in range(0, entities.size()):
|
||||||
|
if not entities[i].get_ref():
|
||||||
|
if to_remove == null:
|
||||||
|
to_remove = Array()
|
||||||
|
to_remove.push_back(i)
|
||||||
|
|
||||||
|
func _fixed_process(delta):
|
||||||
|
collect_entities()
|
||||||
|
|
||||||
|
func _get_camera_center():
|
||||||
|
var vtrans = get_canvas_transform()
|
||||||
|
var top_left = -vtrans.get_origin() / vtrans.get_scale()
|
||||||
|
var vsize = get_viewport_rect().size
|
||||||
|
return top_left + 0.5*vsize/vtrans.get_scale()
|
||||||
|
|
||||||
|
func _draw():
|
||||||
|
if entities.size() > 0:
|
||||||
|
render_target.render_target_clear()
|
||||||
|
render_target.it_changed(_get_camera_center())
|
||||||
|
# gc the shit out of em
|
||||||
|
collect_entities()
|
|
@ -0,0 +1,63 @@
|
||||||
|
[gd_scene load_steps=5 format=1]
|
||||||
|
|
||||||
|
[ext_resource path="res://MinimapControl.gd" type="Script" id=1]
|
||||||
|
[ext_resource path="res://Minimap.gd" type="Script" id=2]
|
||||||
|
[ext_resource path="res://MinimapTarget.gd" type="Script" id=3]
|
||||||
|
[ext_resource path="res://Drawer.gd" type="Script" id=4]
|
||||||
|
|
||||||
|
[node name="MinimapControl" type="CanvasLayer"]
|
||||||
|
|
||||||
|
layer = 1
|
||||||
|
offset = Vector2( 0, 0 )
|
||||||
|
rotation = 0.0
|
||||||
|
scale = Vector2( 1, 1 )
|
||||||
|
script/script = ExtResource( 1 )
|
||||||
|
|
||||||
|
[node name="Minimap" type="Control" parent="."]
|
||||||
|
|
||||||
|
focus/ignore_mouse = false
|
||||||
|
focus/stop_mouse = true
|
||||||
|
size_flags/horizontal = 2
|
||||||
|
size_flags/vertical = 2
|
||||||
|
margin/left = 0.0
|
||||||
|
margin/top = 0.0
|
||||||
|
margin/right = 0.0
|
||||||
|
margin/bottom = 0.0
|
||||||
|
script/script = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="TextureFrame" type="TextureFrame" parent="Minimap"]
|
||||||
|
|
||||||
|
rect/scale = Vector2( 2, 2 )
|
||||||
|
focus/ignore_mouse = true
|
||||||
|
focus/stop_mouse = true
|
||||||
|
size_flags/horizontal = 2
|
||||||
|
size_flags/vertical = 2
|
||||||
|
margin/left = 0.0
|
||||||
|
margin/top = 0.0
|
||||||
|
margin/right = 128.0
|
||||||
|
margin/bottom = 128.0
|
||||||
|
stretch_mode = 0
|
||||||
|
|
||||||
|
[node name="Viewport" type="Viewport" parent="Minimap"]
|
||||||
|
|
||||||
|
rect = Rect2( 0, 0, 128, 128 )
|
||||||
|
own_world = false
|
||||||
|
world = null
|
||||||
|
transparent_bg = false
|
||||||
|
render_target/enabled = true
|
||||||
|
render_target/v_flip = false
|
||||||
|
render_target/clear_on_new_frame = false
|
||||||
|
render_target/filter = false
|
||||||
|
render_target/gen_mipmaps = false
|
||||||
|
render_target/update_mode = 3
|
||||||
|
audio_listener/enable_2d = false
|
||||||
|
audio_listener/enable_3d = false
|
||||||
|
physics/object_picking = false
|
||||||
|
gui/disable_input = false
|
||||||
|
script/script = ExtResource( 3 )
|
||||||
|
|
||||||
|
[node name="Drawer" type="Node2D" parent="Minimap/Viewport"]
|
||||||
|
|
||||||
|
script/script = ExtResource( 4 )
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
extends CanvasLayer
|
||||||
|
|
||||||
|
onready var map = get_node("Minimap")
|
||||||
|
|
||||||
|
var n_frames = 5
|
||||||
|
var frames_passed = 0
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
set_fixed_process(true)
|
||||||
|
|
||||||
|
func _fixed_process(delta):
|
||||||
|
frames_passed += 1
|
||||||
|
if frames_passed >= n_frames:
|
||||||
|
frames_passed = 0
|
||||||
|
map.update()
|
||||||
|
|
||||||
|
func register_entity(e):
|
||||||
|
map.register_entity(e)
|
|
@ -0,0 +1,12 @@
|
||||||
|
extends Viewport
|
||||||
|
|
||||||
|
onready var child = get_node("Drawer")
|
||||||
|
|
||||||
|
func _ready():
|
||||||
|
pass
|
||||||
|
|
||||||
|
func init(ents):
|
||||||
|
child.init(ents)
|
||||||
|
|
||||||
|
func it_changed(new_pos):
|
||||||
|
child.it_changed(new_pos)
|
|
@ -1,6 +1,7 @@
|
||||||
extends KinematicBody2D
|
extends KinematicBody2D
|
||||||
|
|
||||||
onready var sprite = get_node("Sprite")
|
onready var sprite = get_node("Sprite")
|
||||||
|
onready var camera = get_node("Camera2D")
|
||||||
|
|
||||||
var mov_speed = 64 # pixels per second
|
var mov_speed = 64 # pixels per second
|
||||||
var ship_vel = Vector2(0, 0)
|
var ship_vel = Vector2(0, 0)
|
||||||
|
@ -16,7 +17,7 @@ func _ready():
|
||||||
|
|
||||||
func turn_towards(delta, pos):
|
func turn_towards(delta, pos):
|
||||||
|
|
||||||
var target_dir = (pos - get_pos()).normalized()
|
var target_dir = (pos - get_global_pos()).normalized()
|
||||||
var cpd = target_dir.dot(ship_dir.rotated(deg2rad(90)))
|
var cpd = target_dir.dot(ship_dir.rotated(deg2rad(90)))
|
||||||
|
|
||||||
var as = asin(cpd)
|
var as = asin(cpd)
|
||||||
|
@ -27,7 +28,7 @@ func turn_towards(delta, pos):
|
||||||
func _fixed_process(delta):
|
func _fixed_process(delta):
|
||||||
|
|
||||||
var mov_delta = Vector2(0, 0)
|
var mov_delta = Vector2(0, 0)
|
||||||
turn_towards(delta, get_viewport().get_mouse_pos())
|
turn_towards(delta, get_global_mouse_pos())
|
||||||
|
|
||||||
if Input.is_action_pressed("player_move_forwards"):
|
if Input.is_action_pressed("player_move_forwards"):
|
||||||
mov_delta += -ship_dir
|
mov_delta += -ship_dir
|
||||||
|
|
19
Player.tscn
19
Player.tscn
|
@ -16,4 +16,23 @@ script/script = ExtResource( 1 )
|
||||||
|
|
||||||
texture = ExtResource( 2 )
|
texture = ExtResource( 2 )
|
||||||
|
|
||||||
|
[node name="Camera2D" type="Camera2D" parent="."]
|
||||||
|
|
||||||
|
anchor_mode = 1
|
||||||
|
rotating = false
|
||||||
|
current = true
|
||||||
|
zoom = Vector2( 1, 1 )
|
||||||
|
limit/left = -10000000
|
||||||
|
limit/top = -10000000
|
||||||
|
limit/right = 10000000
|
||||||
|
limit/bottom = 10000000
|
||||||
|
drag_margin/h_enabled = true
|
||||||
|
drag_margin/v_enabled = true
|
||||||
|
smoothing/enable = false
|
||||||
|
smoothing/speed = 5.0
|
||||||
|
drag_margin/left = 0.2
|
||||||
|
drag_margin/top = 0.2
|
||||||
|
drag_margin/right = 0.2
|
||||||
|
drag_margin/bottom = 0.2
|
||||||
|
|
||||||
|
|
||||||
|
|
Binary file not shown.
Binary file not shown.
After Width: | Height: | Size: 2.4 KiB |
|
@ -0,0 +1,2 @@
|
||||||
|
filter=false
|
||||||
|
repeat=true
|
Loading…
Reference in New Issue