This commit is contained in:
Harmony Monroe 2020-08-22 18:45:12 -04:00
commit 10369744ba
15 changed files with 641 additions and 0 deletions

15
.gitignore vendored Normal file
View file

@ -0,0 +1,15 @@
# Godot-specific ignores
.import/
export.cfg
export_presets.cfg
# Imported translations (automatically generated from CSV files)
*.translation
# Mono-specific ignores
.mono/
data_*/
# custom
*.import
Export/

6
Font/m3x6.tres Normal file
View file

@ -0,0 +1,6 @@
[gd_resource type="DynamicFont" load_steps=2 format=2]
[ext_resource path="res://Font/m3x6.ttf" type="DynamicFontData" id=1]
[resource]
font_data = ExtResource( 1 )

BIN
Font/m3x6.ttf Normal file

Binary file not shown.

BIN
Image/crate_tiles.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 751 B

38
Scene/Box.tscn Normal file
View file

@ -0,0 +1,38 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Image/crate_tiles.png" type="Texture" id=1]
[ext_resource path="res://Script/Box.gd" type="Script" id=2]
[ext_resource path="res://Font/m3x6.tres" type="DynamicFont" id=3]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 4, 4 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 5, 4 )
[node name="Box" type="KinematicBody2D"]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="."]
texture = ExtResource( 1 )
vframes = 4
hframes = 4
frame = 1
[node name="CollisionShape2D" type="CollisionShape2D" parent="."]
shape = SubResource( 1 )
[node name="RichTextLabel" type="RichTextLabel" parent="."]
visible = false
margin_right = 40.0
margin_bottom = 40.0
custom_fonts/normal_font = ExtResource( 3 )
text = "0,0"
__meta__ = {
"_edit_use_anchors_": false
}
[node name="PushArea2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="PushArea2D"]
shape = SubResource( 2 )

44
Scene/Player.tscn Normal file
View file

@ -0,0 +1,44 @@
[gd_scene load_steps=6 format=2]
[ext_resource path="res://Image/crate_tiles.png" type="Texture" id=1]
[ext_resource path="res://Script/Actor.gd" type="Script" id=2]
[sub_resource type="RectangleShape2D" id=1]
extents = Vector2( 4, 3.5 )
[sub_resource type="RectangleShape2D" id=2]
extents = Vector2( 4, 4 )
[sub_resource type="RectangleShape2D" id=3]
extents = Vector2( 4, 4 )
[node name="Player" type="KinematicBody2D"]
script = ExtResource( 2 )
[node name="SpriteGuy" type="Sprite" parent="."]
texture = ExtResource( 1 )
vframes = 4
hframes = 4
[node name="SpriteBox" type="Sprite" parent="."]
position = Vector2( 0, -7 )
texture = ExtResource( 1 )
vframes = 4
hframes = 4
frame = 1
[node name="CollisionGuy" type="CollisionShape2D" parent="."]
position = Vector2( 0, 0.5 )
shape = SubResource( 1 )
[node name="CollisionBox" type="CollisionShape2D" parent="."]
position = Vector2( 0, -7 )
shape = SubResource( 2 )
[node name="Area2D" type="Area2D" parent="."]
[node name="CollisionShape2D" type="CollisionShape2D" parent="Area2D"]
shape = SubResource( 3 )

123
Scene/scn1.tscn Normal file
View file

@ -0,0 +1,123 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://Image/crate_tiles.png" type="Texture" id=1]
[ext_resource path="res://Script/Player.gd" type="Script" id=2]
[ext_resource path="res://Script/Actor.gd" type="Script" id=3]
[ext_resource path="res://Script/SolidTileMap.gd" type="Script" id=4]
[sub_resource type="ConvexPolygonShape2D" id=1]
points = PoolVector2Array( 0, 0, 8, 0, 8, 8, 0, 8 )
[sub_resource type="ConvexPolygonShape2D" id=2]
points = PoolVector2Array( 8, 8, 0, 8, 0, 0, 8, 0 )
[sub_resource type="TileSet" id=3]
resource_local_to_scene = true
0/name = "crate_tiles.png 0"
0/texture = ExtResource( 1 )
0/tex_offset = Vector2( 0, 0 )
0/modulate = Color( 1, 1, 1, 1 )
0/region = Rect2( 0, 8, 8, 8 )
0/tile_mode = 0
0/occluder_offset = Vector2( 0, 0 )
0/navigation_offset = Vector2( 0, 0 )
0/shape_offset = Vector2( 0, 0 )
0/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
0/shape = SubResource( 1 )
0/shape_one_way = false
0/shape_one_way_margin = 1.0
0/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 1 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
} ]
0/z_index = 0
1/name = "crate_tiles.png 1"
1/texture = ExtResource( 1 )
1/tex_offset = Vector2( 0, 0 )
1/modulate = Color( 1, 1, 1, 1 )
1/region = Rect2( 8, 8, 8, 8 )
1/tile_mode = 0
1/occluder_offset = Vector2( 0, 0 )
1/navigation_offset = Vector2( 0, 0 )
1/shape_offset = Vector2( 0, 0 )
1/shape_transform = Transform2D( 1, 0, 0, 1, 0, 0 )
1/shape = SubResource( 2 )
1/shape_one_way = false
1/shape_one_way_margin = 1.0
1/shapes = [ {
"autotile_coord": Vector2( 0, 0 ),
"one_way": false,
"one_way_margin": 1.0,
"shape": SubResource( 2 ),
"shape_transform": Transform2D( 1, 0, 0, 1, 0, 0 )
} ]
1/z_index = 0
[node name="Node2D" type="Node2D"]
[node name="SolidTileMap" type="TileMap" parent="."]
tile_set = SubResource( 3 )
cell_size = Vector2( 8, 8 )
format = 1
tile_data = PoolIntArray( -458760, 1, 0, -458759, 0, 0, -458758, 0, 0, -458757, 0, 0, -458756, 0, 0, -458755, 0, 0, -458754, 0, 0, -458753, 0, 0, -524288, 0, 0, -524287, 0, 0, -524286, 0, 0, -524285, 0, 0, -524284, 0, 0, -524283, 0, 0, -524282, 0, 0, -524281, 1, 0, -393224, 0, 0, -458745, 0, 0, -327688, 0, 0, -393209, 0, 0, -262152, 0, 0, -262149, 0, 0, -262148, 0, 0, -327677, 0, 0, -327676, 0, 0, -327673, 0, 0, -196616, 0, 0, -196613, 0, 0, -196612, 0, 0, -262141, 0, 0, -262140, 0, 0, -262137, 0, 0, -131080, 0, 0, -196601, 0, 0, -65544, 0, 0, -131065, 0, 0, -8, 0, 0, -65529, 0, 0, 65528, 0, 0, 7, 0, 0, 131064, 0, 0, 65543, 0, 0, 196600, 1, 0, 131079, 0, 0, 262136, 0, 0, 262137, 0, 0, 262138, 0, 0, 262139, 0, 0, 262140, 0, 0, 262141, 1, 0, 196615, 0, 0, 327672, 0, 0, 262151, 0, 0, 393208, 0, 0, 327682, 1, 0, 327683, 0, 0, 327684, 0, 0, 327685, 0, 0, 327686, 0, 0, 327687, 0, 0, 458744, 0, 0, 393218, 0, 0, 393219, 0, 0, 393220, 0, 0, 393221, 0, 0, 393222, 0, 0, 393223, 0, 0, 524280, 1, 0, 524281, 0, 0, 524282, 0, 0, 524283, 0, 0, 524284, 0, 0, 524285, 0, 0, 524286, 0, 0, 524287, 0, 0, 458752, 0, 0, 458753, 0, 0, 458754, 0, 0, 458755, 0, 0, 458756, 0, 0, 458757, 0, 0, 458758, 0, 0, 458759, 1, 0 )
script = ExtResource( 4 )
[node name="Camera2D" type="Camera2D" parent="."]
current = true
[node name="Player" type="Node2D" parent="."]
script = ExtResource( 2 )
[node name="Sprite" type="Sprite" parent="Player"]
texture = ExtResource( 1 )
centered = false
vframes = 4
hframes = 4
frame = 15
[node name="Box" type="Node2D" parent="."]
position = Vector2( 20, 20 )
script = ExtResource( 3 )
[node name="Sprite" type="Sprite" parent="Box"]
texture = ExtResource( 1 )
centered = false
vframes = 4
hframes = 4
frame = 1
[node name="Box2" type="Node2D" parent="."]
position = Vector2( 36, 12 )
script = ExtResource( 3 )
[node name="Sprite" type="Sprite" parent="Box2"]
texture = ExtResource( 1 )
centered = false
vframes = 4
hframes = 4
frame = 1
[node name="Box3" type="Node2D" parent="."]
position = Vector2( -12, 43 )
script = ExtResource( 3 )
[node name="Sprite" type="Sprite" parent="Box3"]
texture = ExtResource( 1 )
centered = false
vframes = 4
hframes = 4
frame = 1
[node name="Box4" type="Node2D" parent="."]
position = Vector2( -40, 40 )
script = ExtResource( 3 )
[node name="Sprite" type="Sprite" parent="Box4"]
texture = ExtResource( 1 )
centered = false
vframes = 4
hframes = 4
frame = 1

218
Script/Actor.gd Normal file
View file

@ -0,0 +1,218 @@
extends Node2D
class_name Actor
var px : int = 0
var py : int = 0
export var hitbox_x : int = 8
export var hitbox_y : int = 8
var speed_x = 0
var speed_y = 0
export var gravity = 0.2
var remainder_x = 0
var remainder_y = 0
export var is_moving = true
export var is_solid = true
export var is_colliding = true
export var is_using_gravity = true
export var is_on_treadmill = false
var has_moved_x = false
var has_moved_y = false
var has_hit_up = false
var has_hit_down = false
var has_hit_left = false
var has_hit_right = false
var is_on_floor = false
var is_on_floor_2 = false
var is_on_floor_3 = false
# Called when the node enters the scene tree for the first time.
func _ready():
px = floor(position.x)
py = floor(position.y)
apply_pos()
Shared.actor_array.append(self)
func _process(delta):
move()
if is_using_gravity:
speed_y += gravity
apply_pos()
# axis aligned bounding box
func aabb(x1 : int, y1 : int, w1 : int, h1 : int, x2 : int, y2 : int, w2 : int, h2 : int):
return x1 < x2 + w2 and x2 < x1 + w1 and y1 < y2 + h2 and y2 < y1 + h1
# check solid tilemap (on x axis)
func check_solid_tile_x(dist : int):
# left / dist == -1
var x = px - 1
# right
if dist == 1:
x = px + hitbox_x
var y1 = py
var y2 = py + hitbox_y - 1
var w2m1 = Shared.node_map.world_to_map(Vector2(x, y1))
var w2m2 = Shared.node_map.world_to_map(Vector2(x, y2))
var check_up = Shared.node_map.get_cellv(w2m1) != -1
var check_down = Shared.node_map.get_cellv(w2m2) != -1
return check_up or check_down
# check solid tilemap (on y axis)
func check_solid_tile_y(dist : int):
# up / dist == -1
var y = py - 1
# down
if dist == 1:
y = py + hitbox_y
var x1 = px
var x2 = px + hitbox_x - 1
var w2m1 = Shared.node_map.world_to_map(Vector2(x1, y))
var w2m2 = Shared.node_map.world_to_map(Vector2(x2, y))
var check_left = Shared.node_map.get_cellv(w2m1) != -1
var check_right = Shared.node_map.get_cellv(w2m2) != -1
return check_left or check_right
# check tilemap, and then check actors (on x axis)
func check_solid_x(dist : int):
var hit = check_solid_tile_x(dist)
if not hit:
hit = check_solid_actor(dist, 0, null)
return hit
# check tilemap, and then check actors (on y axis)
func check_solid_y(dist : int):
var hit = check_solid_tile_y(dist)
if not hit:
hit = check_solid_actor(0, dist, null)
return hit
# check for solid actors, dx, dy = distance x and y
func check_solid_actor(dx : int, dy : int, ignore : Actor):
var hit = false
for a in Shared.actor_array:
if a != self and a.is_solid and a != ignore:
if aabb(px + dx, py + dy, hitbox_x, hitbox_y, a.px, a.py, a.hitbox_x, a.hitbox_y):
hit = true
break
return hit
# move actor
func move():
# clear bools
has_moved_x = false
has_moved_y = false
has_hit_up = false
has_hit_down = false
has_hit_left = false
has_hit_right = false
remainder_y += speed_y
var dy = round(remainder_y) # distance y
remainder_y -= dy
if dy != 0:
move_y(dy)
remainder_x += speed_x
var dx = round(remainder_x) # distance x
remainder_x -= dx
if dx != 0:
move_x(dx)
# return distance of upcoming move
func move_get_dist():
return Vector2(round(remainder_x + speed_x), round(remainder_y + speed_y))
# move x axis
func move_x(dist : int):
var hit = false
has_moved_x = true
if is_colliding:
var step = sign(dist)
for i in range(abs(dist)):
if check_solid_x(step):
speed_x = 0
remainder_x = 0
has_hit_left = (step == -1)
has_hit_right = (step == 1)
hit = true
break
else:
px += step
else:
px += dist
return hit
# move y axis
func move_y(dist : int):
var hit = false
has_moved_y = true
is_on_floor_3 = is_on_floor_2
is_on_floor_2 = is_on_floor
is_on_floor = false
if is_colliding:
var step = sign(dist)
for i in range(abs(dist)):
if check_solid_y(step):
speed_y = 0
remainder_y = 0
has_hit_up = (step == -1)
has_hit_down = (step == 1)
is_on_floor = has_hit_down
hit = true
break
else:
py += step
else:
py += dist
return hit
# return array of overlapping actors
func overlapping_actors(dx : int, dy : int, ignore : Actor):
var act = []
for a in Shared.actor_array:
if a != self and a != ignore:
if aabb(px + dx, py + dy, hitbox_x, hitbox_y, a.px, a.py, a.hitbox_x, a.hitbox_y):
act.append(a)
return act
# update the node's position
func apply_pos():
position.x = px
position.y = py
# remove actor from array and free node
func remove():
Shared.actor_array.erase(self)
queue_free()

30
Script/Player.gd Normal file
View file

@ -0,0 +1,30 @@
extends Actor
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
if btn.p("reset"):
Shared.reload()
var btnx = btn.d("right") - btn.d("left")
var btny = btn.d("down") - btn.d("up")
speed_x = btnx * 0.5
#speed_y = btny * 3
if btn.p("jump") and is_on_floor:
speed_y = -3

17
Script/Shared.gd Normal file
View file

@ -0,0 +1,17 @@
extends Node
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
var actor_array : Array = []
var node_map : TileMap
func reload():
actor_array.clear()
get_tree().reload_current_scene()

17
Script/SolidTileMap.gd Normal file
View file

@ -0,0 +1,17 @@
extends TileMap
# Declare member variables here. Examples:
# var a = 2
# var b = "text"
# Called when the node enters the scene tree for the first time.
func _ready():
Shared.node_map = self
pass # Replace with function body.
# Called every frame. 'delta' is the elapsed time since the previous frame.
#func _process(delta):
# pass

16
Script/btn.gd Normal file
View file

@ -0,0 +1,16 @@
extends Node
func NumBool(arg : bool):
return 1 if arg else 0
# DOWN
func d(arg : String):
return NumBool(Input.is_action_pressed(arg))
# PRESSED
func p(arg : String):
return NumBool(Input.is_action_just_pressed(arg))
# RELEASED
func r(arg : String):
return NumBool(Input.is_action_just_released(arg))

7
default_env.tres Normal file
View file

@ -0,0 +1,7 @@
[gd_resource type="Environment" load_steps=2 format=2]
[sub_resource type="ProceduralSky" id=1]
[resource]
background_mode = 2
background_sky = SubResource( 1 )

BIN
icon.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 7.2 KiB

110
project.godot Normal file
View file

@ -0,0 +1,110 @@
; Engine configuration file.
; It's best edited using the editor UI and not directly,
; since the parameters that go here are not all obvious.
;
; Format:
; [section] ; section goes between []
; param=value ; assign values to parameters
config_version=4
_global_script_classes=[ {
"base": "Node2D",
"class": "Actor",
"language": "GDScript",
"path": "res://Script/Actor.gd"
} ]
_global_script_class_icons={
"Actor": ""
}
[application]
config/name="gdBox"
run/main_scene="res://Scene/scn1.tscn"
config/icon="res://icon.png"
[autoload]
btn="*res://Script/btn.gd"
Shared="*res://Script/Shared.gd"
[display]
window/size/width=128
window/size/height=128
window/size/test_width=1280
window/size/test_height=1280
window/dpi/allow_hidpi=true
window/stretch/mode="2d"
window/stretch/aspect="keep"
[importer_defaults]
texture={
"compress/bptc_ldr": 0,
"compress/hdr_mode": 0,
"compress/lossy_quality": 0.7,
"compress/mode": 0,
"compress/normal_map": 0,
"detect_3d": true,
"flags/anisotropic": false,
"flags/filter": false,
"flags/mipmaps": false,
"flags/repeat": 0,
"flags/srgb": 2,
"process/HDR_as_SRGB": false,
"process/fix_alpha_border": true,
"process/invert_color": false,
"process/premult_alpha": false,
"size_limit": 0,
"stream": false,
"svg/scale": 1.0
}
[input]
up={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777232,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":87,"unicode":0,"echo":false,"script":null)
]
}
down={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777234,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":83,"unicode":0,"echo":false,"script":null)
]
}
left={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777231,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":65,"unicode":0,"echo":false,"script":null)
]
}
right={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":16777233,"unicode":0,"echo":false,"script":null)
, Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":68,"unicode":0,"echo":false,"script":null)
]
}
jump={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":90,"unicode":0,"echo":false,"script":null)
]
}
action={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":88,"unicode":0,"echo":false,"script":null)
]
}
reset={
"deadzone": 0.5,
"events": [ Object(InputEventKey,"resource_local_to_scene":false,"resource_name":"","device":0,"alt":false,"shift":false,"control":false,"meta":false,"command":false,"pressed":false,"scancode":82,"unicode":0,"echo":false,"script":null)
]
}
[rendering]
environment/default_clear_color=Color( 0, 0, 0, 1 )
environment/default_environment="res://default_env.tres"