xxxxxxxxxx
254
let Ground = 480;
let Luffy_Stand;
let Luffy_Stand_Sprites = [];
let Luffy_Stand_Step = 0;
let Luffy_Right;
let Luffy_Right_Sprites = [];
let Luffy_Right_Step = 0;
let Luffy_Left;
let Luffy_Left_Sprites = [];
let Luffy_Left_Step = 0;
let Luffy_Jump_Right;
let Luffy_JumpRight_Sprites = [];
let Luffy_JumpRight_Step = 0;
let Luffy_Jump_Left;
let Luffy_JumpLeft_Sprites = [];
let Luffy_JumpLeft_Step = 0;
let Luffy_Fall;
let Luffy_Fall_Sprites = [];
let Luffy_Fall_Step = 0;
let Luffy_Punch;
let Luffy_Punch_Sprites = [];
let Luffy_Punch_Step = 0;
let RH1;
let RH1_Sprites = [];
let RH1_Step = 0;
let RH2;
let RH2_Sprites = [];
let RH2_Step = 0;
let RH;
let RH_Sprites = [];
let RH_Step = 0;
function preload() {
Luffy_Stand = loadImage("Luffy_Stand.png");
Luffy_Right = loadImage("Luffy_Right.png");
Luffy_Left = loadImage("Luffy_Left.png");
Luffy_Jump_Right = loadImage("Luffy_Jump_Right.png");
Luffy_Jump_Left = loadImage("Luffy_Jump_Left.png");
Luffy_Fall = loadImage("Luffy_Fall.png");
Luffy_Punch = loadImage("Luffy_Punch.png");
RH = loadImage("RH.png");
RH1 = loadImage("RH1.png");
RH2 = loadImage("RH2.png");
}
function setup() {
createCanvas(700, 500);
let Stand_w = int(Luffy_Stand.width/3);
let Right_w = int(Luffy_Right.width/8);
let Left_w = int(Luffy_Left.width/8);
let JumpR_w = int(Luffy_Jump_Right.width/6);
let JumpL_w = int(Luffy_Jump_Left.width/6);
let Fall_w = int(Luffy_Fall.width/2);
let Punch_w = int(Luffy_Punch.width/5);
let RH_w = int(RH.width/12);
let RH1_w = int(RH1.width/7);
let RH2_w = int(RH2.width/5);
for(let s = 0; s < 3; s++) {
Luffy_Stand_Sprites[s] = Luffy_Stand.get(s*Stand_w, 0, Stand_w, Luffy_Stand.height);
}
for(let m = 0; m<8; m++) {
Luffy_Right_Sprites[m] = Luffy_Right.get(m*Right_w, 0, Right_w, Luffy_Right.height);
Luffy_Left_Sprites[m] = Luffy_Left.get(m*Left_w, 0, Left_w, Luffy_Left.height);
}
for(let jr = 0; jr<6; jr++) {
Luffy_JumpRight_Sprites[jr] = Luffy_Jump_Right.get(jr*JumpR_w, 0, JumpR_w, Luffy_Jump_Right.height);
}
for(let jl = 0; jl<6; jl++) {
Luffy_JumpLeft_Sprites[jl] = Luffy_Jump_Left.get(jl*JumpL_w, 0, JumpL_w, Luffy_Jump_Right.height);
}
for(let f = 0; f<6; f++) {
Luffy_Fall_Sprites[f] = Luffy_Fall.get(f*Fall_w, 0, Fall_w, Luffy_Fall.height);
}
for(let p = 0; p<5; p++) {
Luffy_Punch_Sprites[p] = Luffy_Punch.get(p*Punch_w, 0, Punch_w, Luffy_Punch.height);
}
for(let r1=0; r1<7; r1++) {
RH1_Sprites[r1] = RH1.get(r1*RH1_w, 0, RH1_w, RH1.height);
}
for(let r2=0; r2<5; r2++) {
RH2_Sprites[r2] = RH2.get(r2*RH2_w, 0, RH2_w, RH2.height);
}
for(let rh=0; rh<12; rh++) {
RH_Sprites[rh] = RH.get(rh*RH_w, 0, RH_w, RH.height);
}
user = new Luffy();
imageMode(CENTER);
}
function draw() {
background("white");
fill(0);
rect(0, Ground, width, 10);
user.jump_settings();
if (keyIsDown(UP_ARROW) && keyIsDown(LEFT_ARROW)) {user.jump_left(); }
else if (keyIsDown(UP_ARROW) && keyIsDown(RIGHT_ARROW)) {user.jump_right(); }
else if(keyIsDown(DOWN_ARROW) && keyIsDown(LEFT_ARROW)) {user.fall_left(); }
else if(keyIsDown(DOWN_ARROW) && keyIsDown(RIGHT_ARROW)) {user.fall_right(); }
else if (keyIsDown(LEFT_ARROW)) {user.move_left(); }
else if(keyIsDown(RIGHT_ARROW)) {user.move_right(); }
else if(keyIsDown(DOWN_ARROW)) {user.fall(); }
else if (keyIsDown(UP_ARROW)) {user.jump(); }
else if(keyIsDown(80)) {user.punch();}
else if(keyIsDown(83)) {user.redhawk();}
else {user.stand(); }
}
class Luffy {
constructor() {
this.x = width/2;
this.y = height/2;
this.velocity = 0;
this.gravity = 0.3;
this.boost = -10;
this.speed = 10;
this.counter = 0;
}
jump_settings() {
this.velocity += this.gravity;
this.y += this.velocity;
if(this.y > Ground-70) {
this.velocity = 0;
this.y = Ground-70;
if(keyIsDown(LEFT_ARROW) && keyIsDown(UP_ARROW)) {
this.velocity += this.boost;
}
else if(keyIsDown(UP_ARROW) && keyIsDown(RIGHT_ARROW)) {
this.velocity += this.boost;
}
else if(keyIsDown(UP_ARROW)) {
this.velocity += this.boost;
}
}
}
jump_left() {
if (frameCount % (30*0.5) == 0) {
Luffy_JumpLeft_Step = (Luffy_JumpLeft_Step + 1) % 6;
}
this.x -= this.speed/1.5;
image(Luffy_JumpLeft_Sprites[Luffy_JumpLeft_Step], this.x, this.y);
}
jump_right() {
if (frameCount % (30*0.5) == 0) {
Luffy_JumpRight_Step = (Luffy_JumpRight_Step + 1) % 6;
}
this.x += this.speed/1.5;
image(Luffy_JumpRight_Sprites[Luffy_JumpRight_Step], this.x, this.y);
}
fall_left() {
if (frameCount % (30) == 0) {
Luffy_Fall_Step = (Luffy_Fall_Step + 1) % 2;
}
this.y += this.speed;
this.x -= this.speed;
image(Luffy_Fall_Sprites[Luffy_Fall_Step], this.x, this.y);
}
fall_right() {
if (frameCount % (30) == 0) {
Luffy_Fall_Step = (Luffy_Fall_Step + 1) % 2;
}
this.y += this.speed;
this.x += this.speed;
image(Luffy_Fall_Sprites[Luffy_Fall_Step], this.x, this.y);
}
move_left() {
if (frameCount % (30*0.2) == 0) {
Luffy_Left_Step = (Luffy_Left_Step + 1) % 8;
}
this.x -= this.speed;
image(Luffy_Left_Sprites[Luffy_Left_Step], this.x, this.y);
}
move_right() {
if (frameCount % (30*0.2) == 0) {
Luffy_Right_Step = (Luffy_Right_Step + 1) % 8;
}
this.x += this.speed;
image(Luffy_Right_Sprites[Luffy_Right_Step], this.x, this.y);
}
fall() {
if (frameCount % (30) == 0) {
Luffy_Fall_Step = (Luffy_Fall_Step + 1) % 2;
}
this.y += this.speed;
image(Luffy_Fall_Sprites[Luffy_Fall_Step], this.x, this.y);
}
jump() {
if (frameCount % (30*0.5) == 0) {
Luffy_JumpRight_Step = (Luffy_JumpRight_Step + 1) % 6;
}
image(Luffy_JumpRight_Sprites[Luffy_JumpRight_Step], this.x, this.y);
}
stand() {
if (frameCount % (30*0.5) == 0) {
Luffy_Stand_Step = (Luffy_Stand_Step + 1) % 3;
}
image(Luffy_Stand_Sprites[Luffy_Stand_Step], this.x, this.y);
}
punch() {
if (frameCount % (30*0.3) == 0) {
Luffy_Punch_Step = (Luffy_Punch_Step + 1) % 5;
}
image(Luffy_Punch_Sprites[Luffy_Punch_Step], this.x, this.y);
}
redhawk() {
// print(this.counter);
if ((frameCount % (30*0.3) == 0)) {
RH_Step = (RH_Step + 1) % 12;
}
image(RH_Sprites[RH_Step], this.x, this.y);
}
}