im trying to make a game but HP never goes down

Ask gaming related questions (AHK v1.1 and older)
tomtor22
Posts: 7
Joined: 04 Jun 2021, 13:25

im trying to make a game but HP never goes down

21 Jun 2021, 10:59

Code: Select all

#Singleinstance,Force

Player:={x:200, y:200, w:20, h:20, speed:3}
Health:={x:10, y:10, w:100, h:20, HP1:100}

Gui,+AlwaysOnTop
Gui,color, black

gui,add, progress,% "x" Player.x " y" Player.y " w" Player.w " h" Player.h " cWhite BackGroundLime vPlayer_1"

gui,add, progress,% "x" Health.x " y" Health.y " w" Health.w " h" Health.h " cLime BackGroundRed vHealth_HP1"




Gui, show, x800 y100 w500 h500, Game

SetTimer,Move_player,10

HP1:
{
	GuiControl, ,Health.HP1, %HP1% ;Guicontrol, ,Health_Health, "amount of health"
}



return
Guiclose: 
Exitapp

Move_player:

Damage:=10

	if(GetKeyState("up"))
		{
			if(player.y>0)
				player.y-=player.speed
			if(player.y=0)
				Health.HP1-=Damage

		}

		if(Getkeystate("down"))
			{
				if(player.y<500-player.h)
					player.y+=player.speed
				if(player.y=500)
					Health.HP1-=Damage
			}

		if(Getkeystate("left"))
			{
				if(player.x>0)
					player.x-=player.speed
				if(player.x=0)
					Health.HP1-=Damage
			}

		if(Getkeystate("right"))
			{
				if(player.x<500-player.w)
					player.x+=player.speed
				if(player.x=500)
					Health.HP1-=Damage
			}



Guicontrol, Move,Player_1, % "x" player.x " y" player.y
Tooltip,% Health.HP1
 return
[Mod edit: [code][/code] tags added.]
Last edited by gregster on 21 Jun 2021, 11:05, edited 1 time in total.
Reason: Please use [code] tags. Thank you!
swagfag
Posts: 6222
Joined: 11 Jan 2017, 17:59

Re: im trying to make a game but HP never goes down

21 Jun 2021, 13:10

run it with a debugger and see what values u get.
since ure testing for equality and ur position updates in increments of 3, ure probably never hitting those exact thresholds needed to decrease the HP
tomtor22
Posts: 7
Joined: 04 Jun 2021, 13:25

Re: im trying to make a game but HP never goes down

22 Jun 2021, 09:54

@swagfag
thankyou so much but i dunno how to run it in a debugger ;-;

Return to “Gaming Help (v1)”

Who is online

Users browsing this forum: Shoobis and 40 guests