0% found this document useful (0 votes)
14 views5 pages

SP, Ething

Uploaded by

mr.isaiahmck
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views5 pages

SP, Ething

Uploaded by

mr.isaiahmck
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 5

I'm not sure how readable this will be, but here is the code for the TNT

file, the
tween code looks really messy in this format, but the idea was just tween the
sprite
from the shadow to - 70, then back down again, and when that tween finishes change
the state to HIT, play the explosion, flicker the collision for damage on enemies
and
player, then queue free.

the only other tricky thing was having the TNT go where I click. I do global
position - mouse position on the right click when I spawn the TNT, and then I made
the
speed equal to the strength of the distance. kinda hard to explain but I'll post it
too

Player Code:

if Input.is_action_just_pressed("rightClick") and playerCanMove == true and


playerCanThrow == true:

if TNTAmount > 0:

playerCanThrow = false

throwTimer.start()

var rightClickPosition = get\_global\_mouse\_position()

TNTAmount -=1

var TNTInstance = TNT.instance()

get\_parent().add\_child(TNTInstance)

TNTInstance.global\_position = self.global\_position

TNTInstance.direction = (rightClickPosition - self.global\


_position).normalized()

TNTInstance.speed = (abs((rightClickPosition.x - self.global\


_position.x) \* 1.3) + abs((rightClickPosition.y - self.global\_position.y) \*
1.3))

I'm not sure how readable this will be, but here is the code for the TNT file, the
tween code looks really messy in this format, but the idea was just tween the
sprite from the shadow to - 70, then back down again, and when that tween finishes
change the state to HIT, play the explosion, flicker the collision for damage on
enemies and player, then queue free.

the only other tricky thing was having the TNT go where I click. I do global
position - mouse position on the right click when I spawn the TNT, and then I made
the speed equal to the strength of the distance. kinda hard to explain but I'll
post it too

Player Code:

if Input.is_action_just_pressed("rightClick") and playerCanMove == true and


playerCanThrow == true:
if TNTAmount > 0:

playerCanThrow = false

throwTimer.start()

var rightClickPosition = get\_global\_mouse\_position()

TNTAmount -=1

var TNTInstance = TNT.instance()

get\_parent().add\_child(TNTInstance)

TNTInstance.global\_position = self.global\_position

TNTInstance.direction = (rightClickPosition - self.global\


_position).normalized()

TNTInstance.speed = (abs((rightClickPosition.x - self.global\


_position.x) \* 1.3) + abs((rightClickPosition.y - self.global\_position.y) \*
1.3))
TNT Code:

extends KinematicBody2D

onready var sprite = $Sprite

onready var shadow = $Shadow

onready var tween = $Tween

onready var audio = $explosionSound

onready var explosionSprite = $explosion

onready var explosionLight = $explosion/Light2D

onready var hurtArea = $HurtArea/CollisionShape2D

var damage = 10

var speed = 40

var accelleration = 400

var direction = Vector2.ZERO

var velocity = Vector2.ZERO

var travelTime = .38

var distanceInfo = Vector2.ZERO

var knockback_amount = .4

var bullet_direction = Vector2.ZERO

const max_speed = 220


enum{

MOVE

HIT
}

var state = MOVE

func _ready():

hurtArea.disabled = true

randomize()

sprite.rotation = rand\_range(0,90)

tween.interpolate\_property(sprite, "position:y", 0, -70, travelTime, Tween.TRANS\


_CUBIC,Tween.EASE\_OUT)

tween.interpolate\_property(sprite, "position:y", -70, 10, travelTime, Tween.TRANS\


_QUART,Tween.EASE\_IN, travelTime)

tween.interpolate\_property(sprite, "scale:x", 1,.8, travelTime,Tween.TRANS\


_QUART,Tween.EASE\_IN, travelTime)

tween.interpolate\_property(sprite, "scale:y", 1,.8, travelTime,Tween.TRANS\


_QUART,Tween.EASE\_IN, travelTime)

tween.interpolate\_property(shadow, "scale:x", 1,1.5, travelTime,Tween.TRANS\


_QUART,Tween.EASE\_OUT)

tween.interpolate\_property(shadow, "scale:x", 1.5,.7, travelTime,Tween.TRANS\


_QUART,Tween.EASE\_IN, travelTime)

tween.interpolate\_property(shadow, "scale:y", 1,1.5, travelTime,Tween.TRANS\


_QUART,Tween.EASE\_OUT)

tween.interpolate\_property(shadow, "scale:y", 1.5,.7, travelTime,Tween.TRANS\


_QUART,Tween.EASE\_IN, travelTime)

tween.interpolate\_property(shadow, "modulate", Color(1,1,1,1), Color(1,1,1,.5),


travelTime,Tween.TRANS\_QUART,Tween.EASE\_OUT)

tween.interpolate\_property(shadow, "modulate", Color(1,1,1,.5), Color(1,1,1,1),


travelTime,Tween.TRANS\_QUART,Tween.EASE\_IN, travelTime)

tween.start()

yield(tween,"tween\_all\_completed")

sprite.visible = false
shadow.visible = false

state = HIT

audio.play()

explosionSprite.visible = true

explosionSprite.position.y = -5

explosionSprite.play("start")

hurtArea.disabled = false

tween.interpolate\_property(explosionLight, "energy", 2, 0, .5)

tween.start()

yield(explosionSprite,"animation\_finished")

hurtArea.disabled = true

explosionSprite.position.y = 0

explosionSprite.play("end")

yield(explosionSprite,"animation\_finished")

explosionSprite.visible = false

yield(audio,"finished")

queue\_free()

func _process(delta: float):


\#explosionLight.rotation += .005

if speed > max\_speed:

speed = max\_speed

match state:

MOVE:

sprite.rotation += .04

velocity = velocity.move\_toward(direction \* speed, accelleration)

var col = move\_and\_collide(velocity \* delta)

if col:

direction = direction.bounce(col.normal)
HIT:

velocity = velocity.move\_toward(Vector2.ZERO, .5)


func _on_HurtArea_body_entered(body: Node) -> void:
if body.is\_in\_group("enemies") or body.is\_in\_group("special"):

body.OnHit(damage, knockback\_amount, bullet\_direction)

func _on_HurtArea_area_entered(area: Area2D) -> void:


if area.get\_parent().is\_in\_group("enemies") or area.get\_parent().is\_in\
_group("special"):

bullet\_direction = (area.get\_parent().global\_position - self.global\


_position) \* 10

area.get\_parent().OnHit(damage, knockback\_amount, bullet\_direction)

if area.get\_parent().is\_in\_group("player"):

var enemy\_damage = .5

area.get\_parent().invuln(enemy\_damage)

You might also like