Skip to content

Commit

Permalink
Added split screen platformer.
Browse files Browse the repository at this point in the history
  • Loading branch information
reduz committed Sep 14, 2016
1 parent cf98fed commit 10fcf16
Show file tree
Hide file tree
Showing 44 changed files with 2,446 additions and 0 deletions.
9 changes: 9 additions & 0 deletions 2d/split_screen_platformer/bullet.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@

extends RigidBody2D

func _on_bullet_body_enter( body ):
if (body.has_method("hit_by_bullet")):
body.call("hit_by_bullet")

func _on_Timer_timeout():
get_node("anim").play("shutdown")
Binary file added 2d/split_screen_platformer/bullet.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
120 changes: 120 additions & 0 deletions 2d/split_screen_platformer/bullet.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
[gd_scene load_steps=6 format=1]

[ext_resource path="res://bullet.gd" type="Script" id=1]
[ext_resource path="res://bullet.png" type="Texture" id=2]

[sub_resource type="CircleShape2D" id=1]

custom_solver_bias = 0.0
radius = 10.0

[sub_resource type="ColorRamp" id=2]

offsets = FloatArray( 0, 1 )
colors = ColorArray( 1, 1, 1, 1, 1, 0, 0, 0 )

[sub_resource type="Animation" id=3]

length = 1.5
loop = false
step = 0.0
tracks/0/type = "value"
tracks/0/path = NodePath("particles:config/emitting")
tracks/0/interp = 1
tracks/0/imported = false
tracks/0/keys = { "times":FloatArray( 0 ), "transitions":FloatArray( 1 ), "update":1, "values":[ false ] }
tracks/1/type = "value"
tracks/1/path = NodePath("sprite:visibility/self_opacity")
tracks/1/interp = 1
tracks/1/imported = false
tracks/1/keys = { "times":FloatArray( 0, 1.00394 ), "transitions":FloatArray( 1, 1 ), "update":0, "values":[ 1.0, 0.0 ] }
tracks/2/type = "method"
tracks/2/path = NodePath(".")
tracks/2/interp = 1
tracks/2/imported = false
tracks/2/keys = { "times":FloatArray( 1.31 ), "transitions":FloatArray( 1 ), "values":[ { "args":[ ], "method":"queue_free" } ] }

[node name="bullet" type="RigidBody2D"]

input/pickable = false
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
collision/layers = 1
collision/mask = 1
mode = 0
mass = 1.0
friction = 1.0
bounce = 0.0
gravity_scale = 1.0
custom_integrator = false
continuous_cd = 2
contacts_reported = 3
contact_monitor = true
sleeping = false
can_sleep = true
velocity/linear = Vector2( 0, 0 )
velocity/angular = 0.0
damp_override/linear = -1.0
damp_override/angular = -1.0
script/script = ExtResource( 1 )

[node name="particles" type="Particles2D" parent="."]

visibility/opacity = 0.559322
visibility/blend_mode = 1
config/amount = 24
config/lifetime = 0.1
config/local_space = false
config/texture = ExtResource( 2 )
params/direction = 0.0
params/spread = 10.0
params/linear_velocity = 0.0
params/spin_velocity = 0.0
params/orbit_velocity = 0.0
params/gravity_direction = 0.0
params/gravity_strength = 0.0
params/radial_accel = 0.0
params/tangential_accel = 0.0
params/damping = 0.0
params/initial_angle = 0.0
params/initial_size = 1.0
params/final_size = 0.0
params/hue_variation = 0.0
params/anim_speed_scale = 1.0
params/anim_initial_pos = 0.0
color/color_ramp = SubResource( 2 )

[node name="sprite" type="Sprite" parent="."]

texture = ExtResource( 2 )

[node name="CollisionShape2D" type="CollisionShape2D" parent="."]

shape = SubResource( 1 )
trigger = false
_update_shape_index = -1

[node name="Timer" type="Timer" parent="."]

process_mode = 1
wait_time = 1.0
one_shot = true
autostart = true

[node name="anim" type="AnimationPlayer" parent="."]

playback/process_mode = 1
playback/default_blend_time = 0.0
root/root = NodePath("..")
anims/shutdown = SubResource( 3 )
playback/active = true
playback/speed = 1.0
blend_times = [ ]
autoplay = ""

[connection signal="body_enter" from="." to="." method="_on_bullet_body_enter"]

[connection signal="timeout" from="Timer" to="." method="_on_Timer_timeout"]


11 changes: 11 additions & 0 deletions 2d/split_screen_platformer/coin.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

extends Area2D

var taken=false

func _on_coin_body_enter( body ):

if (not taken and body extends preload("res://player.gd")):
get_node("anim").play("taken")
taken=true

Binary file added 2d/split_screen_platformer/coin.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
154 changes: 154 additions & 0 deletions 2d/split_screen_platformer/coin.tscn
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
[gd_scene load_steps=10 format=1]

[ext_resource path="res://coin.gd" type="Script" id=1]
[ext_resource path="res://coin.png" type="Texture" id=2]
[ext_resource path="res://sound_coin.wav" type="Sample" id=3]
[ext_resource path="res://bullet.png" type="Texture" id=4]

[sub_resource type="CircleShape2D" id=1]

custom_solver_bias = 0.0
radius = 10.0

[sub_resource type="Animation" id=2]

resource/name = "spin"
length = 1.5
loop = true
step = 0.25
tracks/0/type = "value"
tracks/0/path = NodePath("sprite:frame")
tracks/0/interp = 1
tracks/0/imported = false
tracks/0/keys = { "times":FloatArray( 0, 0.25, 0.5, 0.75, 1, 1.25, 1.5 ), "transitions":FloatArray( 1, 1, 1, 1, 1, 1, 1 ), "update":1, "values":[ 0, 1, 2, 3, 2, 1, 0 ] }

[sub_resource type="Animation" id=3]

length = 8.0
loop = false
step = 0.0
tracks/0/type = "value"
tracks/0/path = NodePath("sprite:frame")
tracks/0/interp = 1
tracks/0/imported = false
tracks/0/keys = { "times":FloatArray( 0 ), "transitions":FloatArray( 1 ), "update":0, "values":[ 0 ] }
tracks/1/type = "value"
tracks/1/path = NodePath("sound:play/play")
tracks/1/interp = 1
tracks/1/imported = false
tracks/1/keys = { "times":FloatArray( 0 ), "transitions":FloatArray( 1 ), "update":1, "values":[ "coin" ] }
tracks/2/type = "value"
tracks/2/path = NodePath("particles:visibility/self_opacity")
tracks/2/interp = 1
tracks/2/imported = false
tracks/2/keys = { "times":FloatArray( 0, 1.66 ), "transitions":FloatArray( 1, 1 ), "update":0, "values":[ 1.0, 0.0 ] }
tracks/3/type = "value"
tracks/3/path = NodePath("sprite:visibility/self_opacity")
tracks/3/interp = 1
tracks/3/imported = false
tracks/3/keys = { "times":FloatArray( 0, 0.4 ), "transitions":FloatArray( 1, 1 ), "update":0, "values":[ 1.0, 0.0 ] }
tracks/4/type = "value"
tracks/4/path = NodePath("particles:config/emitting")
tracks/4/interp = 1
tracks/4/imported = false
tracks/4/keys = { "times":FloatArray( 0 ), "transitions":FloatArray( 1 ), "update":1, "values":[ true ] }
tracks/5/type = "method"
tracks/5/path = NodePath(".")
tracks/5/interp = 1
tracks/5/imported = false
tracks/5/keys = { "times":FloatArray( 2.7 ), "transitions":FloatArray( 1 ), "values":[ { "args":[ ], "method":"queue_free" } ] }

[sub_resource type="SampleLibrary" id=4]

samples/coin = { "db":0.0, "pitch":1.0, "sample":ExtResource( 3 ) }

[sub_resource type="ColorRamp" id=5]

offsets = FloatArray( 0, 1 )
colors = ColorArray( 1, 1, 1, 1, 0, 0, 0, 1 )

[node name="coin" type="Area2D"]

input/pickable = true
shapes/0/shape = SubResource( 1 )
shapes/0/transform = Matrix32( 1, 0, 0, 1, 0, 0 )
shapes/0/trigger = false
gravity_vec = Vector2( 0, 1 )
gravity = 98.0
linear_damp = 0.1
angular_damp = 1.0
script/script = ExtResource( 1 )

[node name="sprite" type="Sprite" parent="."]

texture = ExtResource( 2 )
hframes = 4

[node name="anim" type="AnimationPlayer" parent="."]

playback/process_mode = 1
playback/default_blend_time = 0.0
root/root = NodePath("..")
anims/spin = SubResource( 2 )
anims/taken = SubResource( 3 )
playback/active = true
playback/speed = 3.0
blend_times = [ ]
autoplay = "spin"

[node name="collision" type="CollisionShape2D" parent="."]

shape = SubResource( 1 )
trigger = false
_update_shape_index = -1

[node name="sound" type="SamplePlayer2D" parent="."]

params/volume_db = 0.0
params/pitch_scale = 1.0
params/attenuation/min_distance = 1.0
params/attenuation/max_distance = 2048.0
params/attenuation/distance_exp = 1.0
config/polyphony = 1
config/samples = SubResource( 4 )
config/pitch_random = 0.0

[node name="particles" type="Particles2D" parent="."]

visibility/blend_mode = 1
config/amount = 8
config/lifetime = 0.4
config/emitting = false
config/half_extents = Vector2( 5, 5 )
config/texture = ExtResource( 4 )
params/direction = 0.0
params/spread = 10.0
params/linear_velocity = 0.0
params/spin_velocity = 0.0
params/orbit_velocity = 0.0
params/gravity_direction = 0.0
params/gravity_strength = 0.0
params/radial_accel = 0.0
params/tangential_accel = 0.0
params/damping = 0.0
params/initial_angle = 0.0
params/initial_size = 0.2
params/final_size = 0.2
params/hue_variation = 0.0
params/anim_speed_scale = 1.0
params/anim_initial_pos = 0.0
color/color_ramp = SubResource( 5 )

[node name="enabler" type="VisibilityEnabler2D" parent="."]

rect = Rect2( -10, -10, 20, 20 )
enabler/pause_animations = true
enabler/freeze_bodies = true
enabler/pause_particles = true
enabler/pause_animated_sprites = true
enabler/process_parent = false
enabler/fixed_process_parent = false

[connection signal="body_enter" from="." to="." method="_on_coin_body_enter"]


58 changes: 58 additions & 0 deletions 2d/split_screen_platformer/enemy.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@

extends KinematicBody2D


const GRAVITY_VEC = Vector2(0,900)
const FLOOR_NORMAL = Vector2(0,-1)

const WALK_SPEED = 70
const STATE_WALKING = 0
const STATE_KILLED = 1

var linear_velocity = Vector2()
var direction = -1
var anim=""

var state = STATE_WALKING

onready var detect_floor_left = get_node("detect_floor_left")
onready var detect_wall_left = get_node("detect_wall_left")
onready var detect_floor_right = get_node("detect_floor_right")
onready var detect_wall_right = get_node("detect_wall_right")
onready var sprite = get_node("sprite")

func _fixed_process(delta):

var new_anim="idle"

if (state==STATE_WALKING):

linear_velocity+= GRAVITY_VEC*delta
linear_velocity.x = direction * WALK_SPEED
linear_velocity = move_and_slide( linear_velocity, FLOOR_NORMAL )

if (not detect_floor_left.is_colliding() or detect_wall_left.is_colliding()):
direction=1.0

if (not detect_floor_right.is_colliding() or detect_wall_right.is_colliding()):
direction=-1.0

sprite.set_scale( Vector2(direction,1.0) )

new_anim="walk"
else:
new_anim="explode"

if (anim!=new_anim):
anim=new_anim
get_node("anim").play(anim)



func hit_by_bullet():
state=STATE_KILLED

func _ready():
set_fixed_process(true)


Binary file added 2d/split_screen_platformer/enemy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading

0 comments on commit 10fcf16

Please sign in to comment.