mirror of https://github.com/profan/ld-39-jam.git
lol, game change much
This commit is contained in:
parent
3db53a43ae
commit
4f1a3fc4ea
|
@ -6,4 +6,6 @@
|
|||
|
||||
[node name="Player" parent="." instance=ExtResource( 1 )]
|
||||
|
||||
transform/pos = Vector2( 92.7742, 71.7896 )
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
[gd_scene format=1]
|
||||
|
||||
[node name="GingerbreadMan" type="AnimatedSprite"]
|
||||
|
||||
animation = "default"
|
||||
|
||||
|
81
Player.gd
81
Player.gd
|
@ -1,67 +1,44 @@
|
|||
extends Node2D
|
||||
|
||||
var mov_direction = Vector2(1, 0)
|
||||
var mov_speed = 128 # pixels per second
|
||||
|
||||
var cur_frame = 0
|
||||
var cur_time_per_frame = 0.1
|
||||
var cur_time = 0
|
||||
var cur_moving = true
|
||||
extends KinematicBody2D
|
||||
|
||||
onready var sprite = get_node("Sprite")
|
||||
|
||||
var mov_speed = 64 # pixels per second
|
||||
var ship_vel = Vector2(0, 0)
|
||||
var ship_max_vel = 100 # pixels per second
|
||||
var ship_accel = 25 # pixels per second.. per second?
|
||||
var ship_turn_speed = deg2rad(360) # degrees per second.. i guess?
|
||||
var ship_mass = 61
|
||||
|
||||
var ship_dir = Vector2(1, 0)
|
||||
|
||||
func _ready():
|
||||
set_fixed_process(true)
|
||||
|
||||
func turn_towards(delta, pos):
|
||||
|
||||
var target_dir = (pos - get_pos()).normalized()
|
||||
var cpd = target_dir.dot(ship_dir.rotated(deg2rad(90)))
|
||||
|
||||
var as = asin(cpd)
|
||||
var ca = clamp(as, (-ship_turn_speed) * delta, (ship_turn_speed) * delta)
|
||||
|
||||
ship_dir = ship_dir.rotated(-ca)
|
||||
|
||||
func _fixed_process(delta):
|
||||
|
||||
var mov_delta = Vector2(0, 0)
|
||||
var mov_direction = Vector2(1, 0)
|
||||
turn_towards(delta, get_viewport().get_mouse_pos())
|
||||
|
||||
# move towards mouse
|
||||
mov_direction = (get_viewport().get_mouse_pos() - get_global_pos()).normalized()
|
||||
|
||||
if Input.is_action_pressed("player_move_forwards") or Input.is_action_pressed("player_move_backwards") or Input.is_action_pressed("player_move_left") or Input.is_action_pressed("player_move_right"):
|
||||
if Input.is_action_pressed("player_move_forwards"):
|
||||
mov_delta.y -= 1 * (mov_speed * delta)
|
||||
# mov_delta = mov_direction * (mov_speed * delta)
|
||||
cur_moving = true
|
||||
mov_delta += -ship_dir
|
||||
elif Input.is_action_pressed("player_move_backwards"):
|
||||
# mov_delta = (-mov_direction) * (mov_speed * delta)
|
||||
mov_delta.y += 1 * (mov_speed * delta)
|
||||
cur_moving = true
|
||||
if Input.is_action_pressed("player_move_left"):
|
||||
mov_delta.x -= 1 * (mov_speed * delta)
|
||||
cur_moving = true
|
||||
elif Input.is_action_pressed("player_move_right"):
|
||||
mov_delta.x += 1 * (mov_speed * delta)
|
||||
cur_moving = true
|
||||
else:
|
||||
cur_moving = false
|
||||
mov_delta += ship_dir
|
||||
|
||||
sprite.set_rot(ship_dir.angle())
|
||||
|
||||
if Input.is_action_pressed("player_attack"):
|
||||
pass
|
||||
var new_vel = (ship_vel + (mov_delta * (delta * ship_accel))).clamped(ship_max_vel)
|
||||
var diff = new_vel - ship_vel
|
||||
ship_vel += diff
|
||||
|
||||
cur_time = cur_time + delta
|
||||
|
||||
if cur_moving and cur_frame != 6:
|
||||
if cur_time > cur_time_per_frame:
|
||||
cur_frame += 1
|
||||
cur_time = 0
|
||||
else:
|
||||
if cur_moving:
|
||||
cur_frame = 1
|
||||
else:
|
||||
cur_frame = 0
|
||||
|
||||
# set frame shit
|
||||
sprite.set_frame(cur_frame)
|
||||
sprite.set_rot(sprite.get_global_pos().angle_to_point(get_viewport().get_mouse_pos()))
|
||||
|
||||
# do teh moves
|
||||
move_local_x(mov_delta.x)
|
||||
move_local_y(mov_delta.y)
|
||||
|
||||
func _process(delta):
|
||||
pass
|
||||
self.move(ship_vel)
|
||||
ship_vel = ship_vel / (delta * ship_mass)
|
||||
|
|
10
Player.tscn
10
Player.tscn
|
@ -1,17 +1,19 @@
|
|||
[gd_scene load_steps=3 format=1]
|
||||
|
||||
[ext_resource path="res://Player.gd" type="Script" id=1]
|
||||
[ext_resource path="res://img/player.atex" type="Texture" id=2]
|
||||
[ext_resource path="res://img/player_ship.tex" type="Texture" id=2]
|
||||
|
||||
[node name="Player" type="Node2D"]
|
||||
[node name="Player" type="KinematicBody2D"]
|
||||
|
||||
transform/scale = Vector2( 2, 2 )
|
||||
input/pickable = false
|
||||
collision/layers = 1
|
||||
collision/mask = 1
|
||||
collision/margin = 0.08
|
||||
script/script = ExtResource( 1 )
|
||||
|
||||
[node name="Sprite" type="Sprite" parent="."]
|
||||
|
||||
texture = ExtResource( 2 )
|
||||
hframes = 7
|
||||
region_rect = Rect2( 0, 0, 32, 32 )
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
[gd_scene format=1]
|
||||
|
||||
[node name="StarBoy" type="AnimatedSprite"]
|
||||
|
||||
animation = "default"
|
||||
|
||||
|
|
@ -1,3 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:e2a064c01847e4578590ff77af82163a17d3bc1d7a4a3637eefaf320428a0e1f
|
||||
size 344
|
||||
oid sha256:0945e8ba6614bccb37c21659b6f9c9b51c3c159eb9c641150c007e2aa2d1789b
|
||||
size 225
|
||||
|
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:ee80f8310c0716d3d0f917da317607e0d9a20fa40ef02c9981f17d1f62bbe44e
|
||||
size 934
|
|
@ -0,0 +1,3 @@
|
|||
version https://git-lfs.github.com/spec/v1
|
||||
oid sha256:4f8b9553f7da9e0500ddfe73a11dcf865060d559fd6c9b929e1bed2aff6c13df
|
||||
size 720
|
Binary file not shown.
After Width: | Height: | Size: 336 B |
Loading…
Reference in New Issue