Akimxiaolong's Forum Posts

  • 1 posts
  • Hey everyone, I hope you are having a nice time, but as you can see, I am having a problem with color.

    My game consists of a person shooting monsters. I added 7 types of monsters now, all into 1 sprite. I am using the free version of construct, so my code can get a bit hard to understand because I have limited events (sorry in advance). for example:

    Monster >> Set Value >> set lives to (int(Self.type = 1) * 5 +

    int(Self.type = 2) * 3 +

    int(Self.type = 3) * 10 +

    int(Self.type = 4) * 7 +

    int(Self.type = 5) * 100 +

    int(Self.type = 6) +

    int(Self.type = 7) * 1000)

    Monster.type defines the type of monster in the game. for example, if the monster type is 3, then he would have 10 lives.

    And so I have been working like this for five days, and everything is working fine! at least, it was. Someone recommended to add a rainbow monster (Monster.type = 7), and so I started working on it.

    They said to me it should have 1000 lives, it should be three times the player's size, it should have a speed of 35 pixels per second and the colour should be, as you expect, rainbow-ish, which will have constant-changing colours, changing every 0.1 seconds. Everything turned out working for the Rainbow monster, except for the most important thing: THE COLOUR.

    for changing the colour, I have used the following code:

    Every 0.1 Seconds:

    Monster >> Add to >> change r by (int(self.type = 7))

    Monster >> Add to >> change g by (int(self.type = 7))

    Monster >> Add to >> change b by (int(self.type = 7))

    Monster >> Set colour to >> Set colour to rgb(self.r, self.g, self.b)

    what I expected is that if Monster.type = 7, then it changes r, g and b by one, and updates every monster's colour. Easy as that.

    except, it broke the whole colour system in the game; sometimes the monsters have the wrong colour, and the rainbow monster doesn't change its colour, which was the code's LITTERAL JOB. like, what in the world???

    I just wanted to change the r g b by 1 if it is a rainbow monster. I don't understand what's the problem.

    here is the code if you need it:

    + System: Every tick

    -> Player: Set angle toward (Mouse.X, Mouse.Y)

    -> scorePrinter: Set text to str(Player.score)

    -> scorePrinter: Set position to (ScrollX - 360, ScrollY - 240)

    -> scorePrinter: Move to top of layer

    >

    + System: Every 6 - difficultyChooser.Value seconds

    -> spawner: Set position to ((floor(random(0, 2)) × 2 - 1) × random(500, 3001) + Player.X, (floor(random(0, 2) × 2 - 1)) × random(500, 3001) + Player.Y)

    -> spawner: Spawn Monster on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Monster: Set type to floor(random(1,8))

    -> Monster: Set spawned to 1

    >

    + System: Every 0.5 seconds

    -> Monster: Set angle toward (Player.X + random(-100, 100), Player.Y + random(-100, 100))

    >

    + System: On start of layout

    -> Audio: Play music.webm looping at volume 0 dB (stereo pan 0, tag "music")

    >

    + Mouse: On Left button Clicked

    -> Player: Spawn Bullet on layer 0 (image point 0, create hierarchy: False, template: "")

    -> Audio: Play gunshot.webm not looping at volume -5 dB (stereo pan 0, tag "")

    >

    + Bullet: On collision with Monster

    -> Bullet: Spawn Explosion on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Explosion: Set size to (25, 61÷70 × 25)

    -> Monster: Subtract 1 from lives

    -> Audio: Play hit-by-bullet.webm not looping at volume - (distance(Monster.X, Monster.Y, Player.X, Player.Y) ÷ 100) dB (stereo pan 0, tag "")

    -> Monster: Bounce Bullet off Bullet

    -> Player: Shake ScrollTo with magnitude 10 ÷ (distance(Monster.X, Monster.Y, Player.X, Player.Y) ÷ 200) for 0.1 seconds (Reducing magnitude)

    -> Bullet: Set angle to -Self.Angle degrees

    -> Bullet: Destroy

    -> Bullet: Spawn Particles on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Particles: Set spray cone to random(40, 70) degrees

    -> Particles: Set particle object to ParticleImg

    -> Particles: Set initial particle size to int(Monster.type = 1)× 15 + int(Monster.type = 2) × 7 + int(Monster.type = 3) × 20 + int(Monster.type = 4) × 15 + int(Monster.type = 5) × 25 + int(Monster.type = 6) × 7 + int(Monster.type = 7) × 25

    -> Particles: Set initial particle speed to 200

    -> Particles: Set particle timeout to 1

    -> Particles: Set rate to int(Monster.type = 1)× 20 + int(Monster.type = 2) × 10 + int(Monster.type = 3) × 30 + int(Monster.type = 4) × 20 + int(Monster.type = 5) × 40 + int(Monster.type = 6) × 10 + int(Monster.type = 7) × 60

    -> Particles: Set initial particle speed randomiser to 100

    -> Particles: Set particle acceleration to -50

    >

    + Player: lives ≤ 0

    -> Player: Shake ScrollTo with magnitude 60 for 1 seconds (Constant magnitude)

    -> menu: Set position to (ScrollX - 70, ScrollY)

    -> Player: Destroy

    -> Explosion: Spawn Explosion on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Explosion: Set size to (100, 87.1428571429)

    -> Audio: Play explosion.webm not looping at volume 300 dB (stereo pan 0, tag "")

    -> Audio: Stop "music"

    -> Player: Spawn Particles on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Particles: Set initial particle speed to 20

    -> Particles: Set initial particle size to 10

    -> Particles: Set particle timeout to 10

    -> Particles: Set rate to 500

    -> Player: Spawn Particles on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Particles: Set initial particle speed to 20

    -> Particles: Set initial particle size to 10

    -> Particles: Set particle timeout to 10

    -> Particles: Set rate to 500

    -> Particles: Set color to rgbEx(128, 128, 128)

    >

    + Monster: spawned = 1

    -> Monster: Start Timer "MonsterSound" for random(2, 5) (Once)

    -> Monster: Set lives to int(Self.type = 1)× 5 + int(Self.type = 2) × 3 + int(Self.type = 3) × 10 + int(Self.type = 4) × 7 + int(Self.type = 5) × 100 + int(Self.type = 6) + int(Self.type=7) × 1000

    -> Monster: Set size to (int(Self.type = 1)× 145 + int(Self.type = 2) × 72.5 + int(Self.type = 3) × 217.5 + int(Self.type = 4) × 145 + int(Self.type = 5) × 290 + int(Self.type = 6) × 52 + int(Self.type=7) × 435, int(Self.type = 1)× 100 + int(Self.type = 2) × 50 + int(Self.type = 3) × 150 + int(Self.type = 4) × 100 + int(Self.type = 5) × 200 + int(Self.type = 6) × 40 + int(Self.type=7) × 300)

    -> Monster: Set Bullet speed to int(Self.type = 1)× 50 + int(Self.type = 2) × 150 + int(Self.type = 3) × 35 + int(Self.type = 4) × 40 + int(Self.type = 5) × 30 + int(Self.type = 6) × 250 + int(Self.type=7) × 35

    -> Monster: Set r to int(Self.type = 1)× 255 + int(Self.type = 2) × 175 + int(Self.type = 3) × 0 + int(Self.type = 4) × 0 + int(Self.type = 5) × 255 + int(Self.type = 6) × 90 + int(Self.type=7) × 255

    -> Monster: Set g to int(Self.type = 1)× 255 + int(Self.type = 2) × 280 + int(Self.type = 3) × 75 + int(Self.type = 4) × 0 + int(Self.type = 5) × 0 + int(Self.type = 6) × 0 + int(Self.type=7) × 127

    -> Monster: Set b to int(Self.type = 1)× 255 + int(Self.type = 2) × 30 + int(Self.type = 3) × 0 + int(Self.type = 4) × 255 + int(Self.type = 5) × 0 + int(Self.type = 6) × 255+ int(Self.type=7) × 0

    -> Monster: Set color to rgbEx(Self.r, Self.g, Self.b)

    -> Monster: Set spawned to 0

    >

    + Monster: lives ≤ 0

    -> Explosion: Spawn Explosion on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Explosion: Set size to (Monster.Width, 61÷70 × Monster.Width)

    -> Audio: Set master volume to (Monster.Width × Monster.Height) ÷ 2 dB

    -> Audio: Play explosion.webm not looping at volume 100 dB (stereo pan 0, tag "")

    -> Audio: Set master volume to 0 dB

    -> Monster: Destroy

    -> Player: Add int(Monster.type = 1)× 5 + int(Monster.type = 2) × 3 + int(Monster.type = 3) × 10 + int(Monster.type = 4) × 7 + int(Monster.type = 5) × 100 + int(Monster.type = 6) to score

    -> Player: Shake ScrollTo with magnitude (int(Monster.type = 1)× 25 + int(Monster.type = 2) × 15 + int(Monster.type = 3) × 50 + int(Monster.type = 4) × 35 + int(Monster.type = 5) × 500 + int(Monster.type = 6) × 10) ÷ (distance(Monster.X, Monster.Y, Player.X, Player.Y) ÷ 200) for 1 seconds (Reducing magnitude)

    -> Monster: Spawn Particles on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Particles: Set spray cone to 360 degrees

    -> Particles: Set particle object to ParticleImg

    -> Particles: Set initial particle size to int(Monster.type = 1)× 15 + int(Monster.type = 2) × 7 + int(Monster.type = 3) × 20 + int(Monster.type = 4) × 15 + int(Monster.type = 5) × 25 + int(Monster.type = 6) × 7 + int(Monster.type = 7) × 25

    -> Particles: Set initial particle speed to 90

    -> Particles: Set particle timeout to 5

    -> Particles: Set rate to int(Monster.type = 1)× 200 + int(Monster.type = 2) × 100 + int(Monster.type = 3) × 300 + int(Monster.type = 4) × 200 + int(Monster.type = 5) × 400 + int(Monster.type = 6) × 100 + int(Monster.type = 7) × 600

    -> Particles: Set initial particle speed randomiser to -100

    >

    + Monster: On collision with Player

    -> Audio: Play man hurt.webm not looping at volume 0 dB (stereo pan 0, tag "")

    -> Player: Subtract 1 from lives

    -> Player: Shake ScrollTo with magnitude 10×(3-Player.lives) for 0.5 seconds (Reducing magnitude)

    -> Player: Spawn Explosion on layer 1 (image point 0, create hierarchy: False, template: "")

    -> Monster: Bounce Bullet off Player

    >

    + Monster: On Timer "MonsterSound"

    -> Audio: Play MonsterSound.webm not looping at volume -distance(Monster.X, Monster.Y, Player.X, Player.Y) ÷ 100 dB (stereo pan 0, tag "")

    -> Monster: Start Timer "MonsterSound" for random(2, 5) (Once)

    >

    + menu: On clicked

    -> Audio: Stop all

    -> System: Go to menu

    -> difficultyChooser: Set visibility Visible

    -> System: Restart layout

    >

    + System: Every 0.1 seconds

    -> Monster: Add int(Self.type = 7) to r

    -> Monster: Add int(Self.type = 7) to g

    -> Monster: Add int(Self.type = 7) to b

    -> Monster: Set color to rgb(Self.r, Self.g, Self.b)

    Thank you in advance for trying to help, and I appreciate it.

    Tagged:

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 1 posts