Game controls

ok ok i know i need alot of help but pls respond to all of my things so basiccally im tryna make an adventure game but i dont know how to code the player to swing his sword and kill the enemies btw if u can be really generous tell me how to make my coded charcter move

here are the codes for moving:
(this is for 4 directions if you need character to go only left and right then remove first two)
if (key=== “up”) {
this.y -=10;
this.rotation = 0;
}if (key=== “down”) {
this.y +=10;
this.rotation = 180;
}if (key=== “left”) {
this.x -=10;
this.rotation = -90;
}if (key=== “right”) {
this.x +=10;
this.rotation = 90;
}

noo no my charcter does move i just want to make an extra keybind button that when it attacks it deletes what ever is in front of it and if ur genourous teaach me how to animate movements

here’s my idea. you can use “this.gotoAndStop()” to move the playhead within a clip. so:

if keyIsPressed(), this.gotoAndPlay(some frame to start walking) [add slimebor’s code]
else, this.gotoAndStop(resting frame)

I was thinking that the objects you want to destroy to have a code like this:

if(this.hitTest(PLAYER)){
___if(isKeyDown(“SPACE”){
______this.remove();
___ }
}

Of-course, swap PLAYER with the name of the character, and SPACE with the key for attacking!
Here, I made this today, it should help if you look at the codes:
shooting and hitting tutorial.wick (95.6 KB)
try it out first and see if it’s what you were looking for
It might look pretty broken since I rushed while making it (had to get started on school work)
Hope it helps :shamrock:

Hi Again Hamza
I just tried your shooter game and tutorial. I want to see the javascript for the bullet and shooter keyboard controller (keyboardcontrol.wickobj). Can you send it to me so I can figure out what you did. Its amazing. Thank you for sharing the program.
Regards
Greg

1 Like

Hi @greg, I sent you a copy of the code
I organized them to make them easier to look through!

I also posted it here for anyone else who prefers having it be written
Frame Four (Game Control Object)

This is the fourth frame, object’s go from right to left with the names, “player,” “test1,” “block”


This is the code for “player”

Here's a quicker way that you could ctrl+c to make life easier:

var speed = 7;
if(isKeyDown(‘left’)){
this.x-=speed;
}
if(isKeyDown(‘right’)){
this.x+=speed;
}
if(this.hitTest(test1)){
this.x-=7;
}


Now this is the code for the object named “block”

Quick ctrl+c

if(this.hitTest(player)){
if(isKeyDown(‘space’)){
this.remove();
}
}

And here’s the code for a quick thing I put so that the character can’t pass through the block

ctrl+c shortcut

if(this.hitTest(player)){
if(isKeyDown(‘space’)){
this.x=9999
}
}

NOTE: Frame five is the exact same as frame four but without the object named “test1”

Frame Three (Shooting)

I’ve made a clip at every part of the screen for the rotation of the object since I had difficulties finding an easier way


I have an easier shortcut, just go to the rotating shooting thing, and plug in this code:

hideCursor();
this.rotation=mouseX;

It should be way faster than my method


Now edit the object ( The shooting thing that I named “one”) and create a tween of a bullet going up! Type “stop();” in the default of the first frame!

Type this in the KeyDown script

if(isKeyDown(‘space’)){
play();
}


And lastly would be the falling things that you shoot!

The code is in the image, and the object, “ender,” is labeled in the background (there’s an arrow pointing at it)

Quick ctrl + c shortcut!

if(this.hitTest(ender)){
this.y=-120.2;
}
this.y+=9;
if(this.hitTest(one)){
this.y=random.integer(-100,10)
}

I hope I didn’t miss any information, let me know if I did!

( btw I also made a ctrl + c section for most of the codes to make life easier )

~ Hamzah Alani

1 Like

@Hamzah_Al_Ani
Many many thanks Hamzah for taking such great effort and time to help me and others learn from your great code. I will look at this today and get back to you if I need help.
Thank you again
Greg

1 Like